1.1.1 • Published 2 months ago

@sebspark/openapi-express v1.1.1

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

@sebspark/openapi-express-router

A typed router for express based on type definitions from openapi-typegen

Usage

Install

yarn add @sebspark/openapi-express`

or

npm install @sebspark/openapi-express`

Generate client type

Use @sebspark/openapi-typegen

Code

import express from 'express'
import { TypedRouter } from '@sebspark/openapi-express'
import { MarketdataServer } from './schemas/marketdata'
import { getMarkets, getMarket } from './markets'

const api: MarketdataServer = {
  '/markets': {
    get: {
      handler: async () => {
        const markets = await getMarkets()
        return [200, {data: markets}]
      },
    },
  },
  '/markets/:id': {
    get: {
      handler: async ({ params }) => {
        const market = await getMarket(params.id)
        return [200, {data: market}]
      },
    },
  },
}

const router = TypedRouter(api)
const app = express()
app.use(router)

Example

Example can be found in @sebspark/openapi-e2e

1.1.1

2 months ago

1.1.0

3 months ago

1.0.0

4 months ago

0.1.0

6 months ago