https://github.com/rwieruch/trpc-openapi-example
tRPC with Open API (Hacker News Edition)
https://github.com/rwieruch/trpc-openapi-example
Last synced: 9 months ago
JSON representation
tRPC with Open API (Hacker News Edition)
- Host: GitHub
- URL: https://github.com/rwieruch/trpc-openapi-example
- Owner: rwieruch
- Created: 2022-10-22T19:44:34.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-22T19:52:41.000Z (about 3 years ago)
- Last Synced: 2025-04-11T11:04:22.567Z (9 months ago)
- Language: TypeScript
- Size: 71.3 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tRPC with Open API (Hacker News Edition)
- feat. [Hacker News' API](https://hn.algolia.com/api)
## Motivation
- mirror a REST API which is out of your control (here Hacker News' API) with [tRPC](https://trpc.io/): 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:
```sh
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`