rwieruch / trpc-openapi-example

tRPC with Open API (Hacker News Edition)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tRPC with Open API (Hacker News Edition)

Motivation

  • mirror a REST API which is out of your control (here Hacker News' API) with tRPC: introduce manually TypeScript for this API and therefore TypeScript support for your client-side application (not included here)
  • generate an Open API (Swagger) documentation
  • run tests (see: src/search/test.ts) of the "out of control" API's response against your controlled type definitions (see: src/search/index.ts)

Get Started

Install and start:

yarn install
yarn start

Visit http://localhost:4000/ for Swagger UI

  • open /v1/search and "Try it out"
  • e.g. { query: 'react' } or { query: 'react', page: '1' }

Visit http://localhost:4000/api/v1/search?query=react or http://localhost:4000/api/v1/search?query=react&page=1 for the mirrored API endpoint

Optionally run tests against your mirrored API vs remote API: yarn test

About

tRPC with Open API (Hacker News Edition)


Languages

Language:TypeScript 100.0%