Taking this example on how to build a Function in JS from the docs:
export default async ({ req, res, log }) => {
switch (req.query.type) {
case 'empty':
return res.empty();
case 'json':
return res.json({"type": "This is a JSON response"});
case 'redirect':
return res.redirect("https://appwrite.io", 301);
case 'html':
return res.send(
"<h1>This is an HTML response</h1>", 200, {
"content-type": "text/html"
});
default:
return res.send("This is a text response");
}
}
I wonder if there's some documentation on the typing of req
, res
and log
? Or even better a dependency I can pull in for it... I actually develop in TypeScript and use Bun for execution, and not having any typing is hard. E.g. can I pass a status code to res.json()
? Which parameter would it be? Will it always be the second one? Can I always send headers on the third parameter? What's the fourth parameter?
I found a comment in one of the projects, which hints to types, but it's a comment (not code or types) and it's not complete: https://github.com/appwrite/functions-starter/blob/main/node-18.0/src/index.js
Recommended threads
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...