Package Exports
- itty-router
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (itty-router) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
itty-router
It's an itty bitty router. That means small. It's tiny. For reals.
Installation
yarn add itty-routeror if you've been transported back to 2017...
npm install itty-routerOur Goals
- have a simple express-like (or better) interface
- have a chainable interface!
- be tiny
- be easy to use/implement
- have as few dependencies as possible (or none)
- have test coverage
- have a README
- have a way to release
- have pretty code
- handle all the basics of routing within a serverless function
- be platform agnostic (or handle the responses of the major platforms)
Example
import { Router } from 'itty-router'
const router = new Router()
// basic GET routs
router.get('/todos', async () => new Response('list of todos'))
router.get('/todos/:id', async ({ params }) => new Response(`details for todo #${params.id}`))
// plus DELETE, PATCH, PUT, POST, etc
router.post('/todos', async () => new Response('created a new todo!'))
// doesn't lose query params...
router.get('/search', async ({ query }) => new Response(JSON.stringify(query)) ?q=foo ---> { q: 'foo' }
// USE IT! (with some sort of event with request object on it)
// Example for CloudFlare Functions... warning this will definitely change.
addEventListener('fetch', router.handle(event))Testing & Contributing
- fork repo
- add code
- run tests (and add your own)
yarn test - submit PR
- profit