@sebspark/openapi-express
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

@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

Readme

Keywords

none

Package Sidebar

Install

npm i @sebspark/openapi-express

Weekly Downloads

408

Version

2.0.0

License

Apache-2.0

Unpacked Size

17.7 kB

Total Files

7

Last publish

Collaborators

  • johanobrink
  • alexanderczigler
  • raduachim
  • believer