
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
- Unable to add permission when creating a...
I am creating a collection from a cloud function using the Appwrite Dart server SDK, and I want to add permissions so it can be accessed by users. I added code ...
- Create owner team member with Server fun...
I understand that when creating a team with a function, the user that made the request will not be the owner so I think I have to add the user that did the requ...
- Schedule a function job with timezone
I am aware that cron schedule will work on UTC timezone. I would like to run my function at a particular time everyday in new york time. If I use UTC, it will m...
