Rank 4: Virtual Machine
I have the api route in nextjs. then I connect via client app. what is best way to send the quries to the api route. I want to build the query string using the client sdk. is this possible
Votes
0
Replies
5
Participants
Unknown
Messages
6
Rank 4: Virtual Machine
I have the api route in nextjs. then I connect via client app. what is best way to send the quries to the api route. I want to build the query string using the client sdk. is this possible
So you're wanting to make a rest call, and add queries to it?
You can do something like this if that is the case
export function generateQueryList(queries: Query[]) { const queryList: string[] = [];
queries.forEach((x) => { queryList.push(`queries[]=${x}`); });
return queryList.join("&");}And you'd use it like this.
/** * Retrieves a list of documents from a specific collection. * * @template {T} - The type of the documents to retrieve. * @param {string} collectionId - The ID of the collection to retrieve documents from. * @returns A promise that resolves to an array of documents of type T. */ async list<T extends Models.Document>( collectionId: string, queries: string[] = [], ) { const queryList = generateQueryList(queries);
const url = `${ENDPOINT}/databases/${DATABASE_ID}/collections/${collectionId}/documents${queries.length > 0 ? `?${queryList.toString()}` : ""}`;
const response = await fetch(url, { headers: { "x-appwrite-project": PROJECT_ID, }, cache: "no-store", });
const result: T = await response.json();
return result; },};Rank 4: Virtual Machine
@Kenny yes something like that. then in server, how to parse it back
Not sure I understand what you mean by parse it back /:
Rank 4: Virtual Machine
i'm not using the rest to appwrite directly. i will use node-appwrite sdk in server as normal. jusst i need to send rest from client via api