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;
},
};
@Kenny yes something like that. then in server, how to parse it back
Not sure I understand what you mean by parse it back /:
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
Recommended threads
- Help with nameservers
I just added our domain, and as per instruction in the page following, it says, "Add the following nameservers on your DNS provider. ..." I want to keep my cu...
- Problem with Appwrite CLI: Removing data...
I'm having an issue with the CLI while trying to manage multiple databases within a single project. My goal is to simplify my local environment by only includin...
- Clean 1.9.0 install, trying to access Ap...
I've been using Appwrite cloud for several months now, it's great and I love it. Doing some local testing so I setup a new Docker image on a Mini PC. Install fa...