1.0.0-rc.19 • Published 3 months ago
@exobase/use-router v1.0.0-rc.19
title: 'useRouter' description: 'A hook to route requests to Exobase handlers'
group: 'Hooks'
Provides an Exobase hook that does method + url routing using a trie based on the given url path.
Install
yarn add @exobase/use-router
# or
yarn add @exobase/hooks
Import
import { useRouter } from '@exobase/use-router'
// or
import { useRouter } from '@exobase/hooks'
Usage
import https from 'https'
import { error } from '@exobase/core'
import { compose, toInt } from 'radash'
import { useRouter } from '@exobase/hooks'
import { useNode } from '@exobase/use-node'
const server = https.createServer(
compose(
useNode(),
useRouter(router =>
router
.put('/v1/library/book/{id}/return', returnBook)
.post('/v1/library/book', createBook)
.get('/v1/library/book/{id}', findBook)
.get('/v1/library/book', listBooks)
),
async () => {
throw error({
status: 404,
message: 'Not found'
})
}
)
)
const port = toInt(process.env.PORT, 8500)
server.listen(port, () => {
console.log(`API listening on port ${port}`)
})
1.0.0-rc.19
3 months ago
1.0.0-rc.18
3 months ago
1.0.0-rc.17
3 months ago
1.0.0-rc.16
3 months ago
1.0.0-rc.14
1 year ago
1.0.0-rc.13
1 year ago
1.0.0-rc.12
1 year ago
1.0.0-rc.11
1 year ago
1.0.0-rc.9
1 year ago
1.0.0-rc.10
1 year ago
1.0.0-rc.7
1 year ago
1.0.0-rc.8
1 year ago
1.0.0-rc.5
1 year ago
1.0.0-rc.6
1 year ago
1.0.0-rc.3
1 year ago
1.0.0-rc.4
1 year ago
1.0.0-rc.2
1 year ago
1.0.0-rc.1
1 year ago