Create an HTTP Server
An API specification is only useful when clients and servers adhere to its rules.
io-ts-http
API specifications are not coupled to any particular HTTP server. api-ts
provides helper libraries that wrap your favorite web server and use the TypeScript
type-checker to ensure your server implementation satisfies the target API
specification.
Create an HTTP server implementing your API specification
We'll use express as our underlying web server in this tutorial.
First, edit your package.json
file to add a few new dependencies (highlighted):
And install them by running:
$ npm install
Next, create a new file server.ts
:
Compile and run server.ts
:
$ npm run build$ node ./server.js
Finally, submit an HTTP request to your server in a web browser or using a new terminal:
$ curl localhost:3000/hello/world"Hello, world!"