Socket
Socket
Sign inDemoInstall

itty-router

Package Overview
Dependencies
1
Maintainers
1
Versions
264
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    itty-router

It's an itty bitty router. That means small. It's tiny. For reals.


Version published
Weekly downloads
28K
decreased by-20.43%
Maintainers
1
Install size
112 kB
Created
Weekly downloads
 

Readme

Source

itty-router

It's an itty bitty router. That means small. It's tiny. For reals.

Installation

yarn add itty-router

or if you've been transported back to 2017...

npm install itty-router

Our 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

  1. fork repo
  2. add code
  3. run tests (and add your own) yarn test
  4. submit PR
  5. profit

FAQs

Last updated on 16 Apr 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc