Middleware 
Middleware > withParams - itty-router 
 
 
withParams simply allows you to request route params directly from the Request itself, rather than through request.params. It does this by adding a fallback - if request['your param name'] isn't found, it tries again from request.params['your param name'].
That's all it does.
Example: without withParams 
ts
router.get('/items/:id', ({ params }) => `Your id is ${params.id}.`)Example: with withParams 
ts
router.get('/items/:id', withParams, ({ id }) => `Your id is ${id}.`)Including Globally 
If using withParams, it's suggested to leverage this upstream (globally), rather than for each individual route.
Here's how to do it using each available Router:
ts
import { AutoRouter } from 'itty-router'
// withParams is included by default
const router = AutoRouter()
router
  .get('/items/:id', ({ id }) => `Your id is ${id}.`)ts
import { Router, withParams } from 'itty-router'
// add withParams to the before stage
const router = Router({ before: [withParams] })
router
  .get('/items/:id', ({ id }) => `Your id is ${id}.`)
// or add it to routes
router
  .get('/items/:id', withParams, ({ id }) => `Your id is ${id}.`)ts
import { IttyRouter, withParams } from 'itty-router'
const router = IttyRouter()
router
  .all('*', withParams)
  .get('/items/:id', ({ id }) => `Your id is ${id}.`)
// or add it to routes
router
  .get('/items/:id', withParams, ({ id }) => `Your id is ${id}.`)Notes 
- AutoRouterincludes- withParamsby default as a convenience.
- For the fastest possible performance, use Routerinstead ofAutoRouterand do not usewithParams. The additional proxy layer over theRequestobject will fractionally slow down all requests of it.
