An open API service indexing awesome lists of open source software.

https://github.com/perongh/funweb

Declarative & Functional Web Backend Framework
https://github.com/perongh/funweb

Last synced: about 2 months ago
JSON representation

Declarative & Functional Web Backend Framework

Awesome Lists containing this project

README

        

# funweb

Functional Web Backend Framework

## Example

```typescript
import {
catchError,
get,
internalServerError,
post,
route,
routes,
verbs,
} from "jsr:@pixel/funweb";

const handler = routes(
route(
"/api/v1",
verbs(
get((req) => Response.json(Object.fromEntries(req.headers))),
post((req) => new Response(req.body)),
),
),
route(
"/?(*.{html,htm})",
(req) => new Response(new URL(req.url).pathname),
),
route(
"/**/error",
() => {
throw new Error("An error occurred");
},
),
catchError((req) => {
console.error(req.error);
return internalServerError(req);
}),
);

Deno.serve(handler);
```