1.0.0-rc.20 • Published 11 months ago

@exobase/use-router v1.0.0-rc.20

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.20

11 months ago

1.0.0-rc.19

1 year ago

1.0.0-rc.18

1 year ago

1.0.0-rc.17

1 year ago

1.0.0-rc.16

1 year ago

1.0.0-rc.14

2 years ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.9

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.3

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago