Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonvasin/routeno
Small, zero-dependency router for Deno using URLPattern
https://github.com/antonvasin/routeno
deno router urlpattern
Last synced: about 1 month ago
JSON representation
Small, zero-dependency router for Deno using URLPattern
- Host: GitHub
- URL: https://github.com/antonvasin/routeno
- Owner: antonvasin
- Created: 2022-06-24T16:36:58.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-01T15:11:55.000Z (10 months ago)
- Last Synced: 2024-10-12T22:47:22.542Z (2 months ago)
- Topics: deno, router, urlpattern
- Language: TypeScript
- Homepage:
- Size: 13.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# routeno
Small opinionated router for Deno.
- Uses `URLPattern` for route matching which supports Express-like route params
- Does not extend `Request` or have any helper functions
- Strives to be very simple and very minimal## Usage
```typescript
import { createRouter } from "https://deno.land/x/[email protected]/mod.ts";
import { serve } from "https://deno.land/[email protected]/http/mod.ts";function getProject(req: Request, params: Record<"id", string>) {
return new Response(getProjectById(params.id));
}const router = createRouter({
"/api/projects": {
"GET": getProjects,
"POST": createProject,
},
"/api/projects/:id": {
"GET": getProject,
},
"/api/check": check, // Will respond to any HTTP method
});await serve(router);
```## Design
Goal is to have tiny wrapper around standard `Request`, `Response` and
`URLPattern` workflow.It doesn't have middleware interface (e.g. `router.get('/route', endpoint)`) and
accepts mapping object instead.Router does not extend default `Request` object and instead passes route params
as second argument to handler function.## Performance
This router written to be as fast as possible while using `URLPattern` (which
uses `path-to-regexp`), which is slower than, e.g. using Radix Trees or RegEx
for matching.Benchmark script with comparison to several popular Deno routers is available.
Run it with `deno bench --unstable`.