Add `/api` routes that return data in JSON format
Created by: noClaps
Adds /api/communities
that returns an object with the following type:
type Response = {
communities: {
id: string;
name: string;
about: string | null;
noMembers: number;
lastActivityAt: string; // time
createdAt: string; // time
proPic: {
url: string;
} | null
}[]
}
Adds /api/search
that takes q
and sort
query parameters. If q
is missing, error 400 is returned. If no results are found, error 404 is returned. Otherwise, an object with the following type is returned:
type Response = {
results: {
id: string;
name: string;
about: string | null;
noMembers: number;
lastActivityAt: string; // time
createdAt: string; // time
proPic: {
url: string;
} | null
}[]
}
where the results
object contains the search results, sorted by relevance by default. The available options for sorting are:
-
relevance
: the default sort if nosort
value is provided -
name-ascending
: sort by name (A-Z) -
name-descending
: sort by name (Z-A) -
activity-ascending
sort by activity (oldest to newest) -
activity-descending
sort by activity (newest to oldest) -
created-ascending
sort by creation date (oldest to newest) -
created-descending
sort by creation date (newest to oldest)