https://github.com/kaibun/appwrite-fn-router
A router for Appwrite’s FaaS
https://github.com/kaibun/appwrite-fn-router
appwrite appwrite-function itty itty-router micro-router
Last synced: 5 months ago
JSON representation
A router for Appwrite’s FaaS
- Host: GitHub
- URL: https://github.com/kaibun/appwrite-fn-router
- Owner: kaibun
- Created: 2025-08-04T23:37:34.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-08-16T13:40:20.000Z (5 months ago)
- Last Synced: 2025-08-16T15:29:05.004Z (5 months ago)
- Topics: appwrite, appwrite-function, itty, itty-router, micro-router
- Language: TypeScript
- Homepage: https://appwrite-fn-router.appwrite.network/
- Size: 6.68 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Appwrite Function Router
This library is a wrapper for [Itty’s `Router`](https://itty.dev/itty-router/concepts), tailored to the constraints of [Appwrite’s FaaS](https://appwrite.io/docs/products/functions/develop) implementation.
## Usage
```ts
import type { AppwriteContext, AppwriteResponseObject, JSONObject } from "appwrite-fn-router"
import { handleRequest } from "appwrite-fn-router";
import { myRouteHandler } from "./routes";
// Optionally define a custom JSON response schema:
type MyJSONResponse = {
status: 'success' | 'error';
message: string;
error?: string;
} & JSONObject;
// This async function is your regular Appwrite’s mandatory function handler:
export default async (context: AppwriteContext) => {
// One may leverage Appwrite’s provided context properties if need be:
// const { req, res, log, error } = context;
// Those properties would be accessible from within the routes handlers thanks
// to the JavaScript closure, but one may import handlers from a file, so
// the best practice here is to pass that context alongside your routes
// (defined using Itty’s API): the context is made available to the route
// handlers):
return handleRequest(context, (router) => {
// In a route handler, request is a native Request object, while req is the
// Appwrite’s specific request flavor. You also get access to the rest of
// Appwrite’s function’s context: res, log and error objects.
router.get('/hello', (request, req, res, log, error) => {
return res.json({
status: 'success',
message: 'Hello, world!',
}) satisfies AppwriteResponseObject;
});
router.post('/data', async (request, req, res, log, error) => {
const data = await req.bodyJson;
return res.json({
received: data,
});
});
// Despite being defined outside the closure, myRouteHandler still has
// access to the function’s context, through it’s params. How handy!
router.get("/mystery", myRouteHandler);
});
```
## Local Development
For instructions on how to set up a local development environment with hot-reloading, please see the [**Contributing Guide**](./doc/docs/contributing/index.md).