sinclairnick / webroute

🕸️ Web APIs, from the route up
https://webroute.vercel.app/docs
MIT License
55 stars 2 forks source link

Core: Add a `.use` method for applying arbitrary middleware #17

Closed sinclairnick closed 5 months ago

sinclairnick commented 5 months ago

This will improve composability of routes a la

const publicRoute = route().use(...)

// ...
publicRoute.handle(() => {})

It will also enable more ergonomic middleware usage with registering routes the non-express way

sinclairnick commented 5 months ago

Perhaps this should not be .use and should rather be handle(...handlers) to be more express-ive?

sinclairnick commented 5 months ago

On the other hand, .use is more composable.

A good UX might look like:

.use<{ user: User }>(hasUser)
//    ^ is merged with Req type
.handle(req => req.user.isDefined)