-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: separate tutorials from how-to guides #1027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,13 @@ sidebar_position: 1 | |
|
||
# Create an API Specification | ||
|
||
Use `@api-ts/io-ts-http` to define a standalone **API specification** in TypeScript. | ||
Learn to define a standalone **API specification** in TypeScript using | ||
`@api-ts/io-ts-http`. | ||
|
||
## What problem does `io-ts-http` solve? | ||
## Understanding API Contracts | ||
|
||
Web services use an [API] as a contract to describe how _clients_ should communicate | ||
with _servers_. | ||
Web services use an [API] as a contract to describe how _clients_ communicate with | ||
_servers_. | ||
|
||
When a server receives a request from a client, the server needs to answer a few | ||
questions before it can begin fulfilling that request: | ||
|
@@ -26,8 +27,8 @@ questions before it can begin fulfilling that request: | |
|
||
We'll call the first _type analysis_ and the second _semantic analysis_. | ||
|
||
`io-ts-http` lets you define API contracts to an **arbitrary degree of precision**, | ||
removing the burden of semantic analysis from your business logic. | ||
`io-ts-http` enables defining API contracts to an **arbitrary degree of precision**, | ||
removing the burden of semantic analysis from business logic. | ||
|
||
[api]: https://en.wikipedia.org/wiki/API | ||
|
||
|
@@ -41,7 +42,7 @@ $ mkdir api-ts-example | |
$ cd api-ts-example | ||
``` | ||
|
||
In your new directory, create a `package.json` file: | ||
In the new directory, create a `package.json` file: | ||
|
||
```json package.json | ||
{ | ||
|
@@ -91,7 +92,7 @@ export const API = apiSpec({ | |
}); | ||
``` | ||
|
||
Compile your API specification with: | ||
Compile the API specification with: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We follow the Microsoft Writing Style Guide, which encourages you to speak to your reader using second-person pronouns: https://learn.microsoft.com/en-us/style-guide/grammar/person I'm slightly hoping the framing of "your API specification" helps the reader feel a sense of attachment to their spec and the journey they're on |
||
|
||
``` | ||
$ npm run build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,16 @@ sidebar_position: 3 | |
|
||
# Create an HTTP Client | ||
|
||
Learn how API specifications enable type-safe communication between clients and servers. | ||
|
||
`io-ts-http` API specifications are not coupled to any particular HTTP client. `api-ts` | ||
provides helper libraries that wrap your favorite HTTP client and use the TypeScript | ||
type-checker to ensure type-safe communication with a server implementing an | ||
provides helper libraries that integrate with various HTTP clients and use the | ||
TypeScript type-checker to ensure type-safe communication with a server implementing an | ||
`io-ts-http` specification. | ||
|
||
## Create a type-safe HTTP Client from an API specification | ||
## Building a type-safe HTTP Client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quibbles:
However, one alternative could be
|
||
|
||
As before, first edit your `package.json` file to add our new dependencies | ||
As in previous steps, first edit the `package.json` file to add new dependencies | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This replaces 1 word with 3, which works against minimalism and brevity |
||
(highlighted): | ||
|
||
```json package.json focus=10,12,17 | ||
|
@@ -37,7 +39,7 @@ As before, first edit your `package.json` file to add our new dependencies | |
} | ||
``` | ||
|
||
And install them by running: | ||
Install them by running: | ||
|
||
``` | ||
$ npm install | ||
|
@@ -71,14 +73,14 @@ main(); | |
|
||
Notice the inferred type of `response.body`. | ||
|
||
Compile and run `client.ts` (make sure your server is still running!): | ||
Compile and run `client.ts` (ensure the server is running): | ||
|
||
``` | ||
$ npm run build | ||
$ node ./client.js | ||
``` | ||
|
||
You will see output like | ||
The output will be: | ||
|
||
``` | ||
Response is: Hello, world! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,19 @@ sidebar_position: 2 | |
|
||
# Create an HTTP Server | ||
|
||
An API specification is only useful when clients and servers adhere to its rules. | ||
Learn how API specifications enable type-safe communication between clients and servers. | ||
|
||
`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. | ||
provides helper libraries that integrate with various web servers and use the TypeScript | ||
type-checker to ensure server implementations satisfy the target API specification. | ||
|
||
## Create an HTTP server implementing your API specification | ||
## Building a server with your API specification | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I think the source text is preferred here, since it is active voice and present tense, and describes more qualities of the final HTTP server |
||
|
||
We'll use [express] as our underlying web server in this tutorial. | ||
This tutorial uses [express] as the underlying web server. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of the word "the" in this way doesn't quite sit right with me, for a reason I can't fully explain. Maybe it's a native speaker thing or maybe I'm just nuts! 😄 To try to put it into words, "the" ought to refer to something previously introduced (or I suppose about to be introduced) but we never introduce that thing, which would be "your service".
But again, we have the opportunity to follow the MWSG and speak directly to our audience in second-person pronouns. |
||
|
||
[express]: https://github.com/expressjs/express | ||
|
||
First, edit your `package.json` file to add a few new dependencies (highlighted): | ||
First, edit the `package.json` file to add a few new dependencies (highlighted): | ||
|
||
```json package.json focus=7,9,13,14 | ||
{ | ||
|
@@ -39,7 +38,7 @@ First, edit your `package.json` file to add a few new dependencies (highlighted) | |
} | ||
``` | ||
|
||
And install them by running: | ||
Install them by running: | ||
|
||
``` | ||
$ npm install | ||
|
@@ -77,7 +76,7 @@ $ npm run build | |
$ node ./server.js | ||
``` | ||
|
||
Finally, submit an HTTP request to your server in a web browser or using a new terminal: | ||
Test the server by submitting an HTTP request in a web browser or using a new terminal: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally favor the source text here too, citing 2nd person MSGW advice |
||
|
||
``` | ||
$ curl localhost:3000/hello/world | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,19 +2,21 @@ | |||||
sidebar_position: 4 | ||||||
--- | ||||||
|
||||||
# Render an OpenAPI specification | ||||||
# Render an OpenAPI Specification | ||||||
|
||||||
Learn how to generate OpenAPI specifications from `io-ts-http` API definitions. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
An `io-ts-http` specification contains a superset of an [OpenAPI] specification. | ||||||
`api-ts` provides `@api-ts/openapi-generator` to produce an OpenAPI specification from | ||||||
your `io-ts-http` API specification. This lets you plug your API specification into the | ||||||
existing OpenAPI ecosystem to HTTP clients for languages other than TypeScript. These | ||||||
clients won't be as ergonomic or type-safe as an `api-ts` HTTP client. | ||||||
an `io-ts-http` API specification. This enables integration with the existing OpenAPI | ||||||
ecosystem to generate HTTP clients for languages other than TypeScript. These clients | ||||||
won't be as ergonomic or type-safe as an `api-ts` HTTP client. | ||||||
|
||||||
[openapi]: https://www.openapis.org/ | ||||||
|
||||||
## Use `openapi-generator` | ||||||
## Working with `openapi-generator` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer the source text, present tense, active voice, minimalism |
||||||
|
||||||
As before, first edit your `package.json` file to add our new dependencies | ||||||
As in previous steps, first edit the `package.json` file to add new dependencies | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer the source text, present tense, active voice, minimalism, 2nd person rule |
||||||
(highlighted): | ||||||
|
||||||
```json package.json focus=15 | ||||||
|
@@ -41,13 +43,13 @@ As before, first edit your `package.json` file to add our new dependencies | |||||
} | ||||||
``` | ||||||
|
||||||
And install it by running: | ||||||
Install it by running: | ||||||
|
||||||
``` | ||||||
$ npm install | ||||||
``` | ||||||
|
||||||
The `openapi-generator` requires our TypeScript compiler settings to be specified in a | ||||||
The `openapi-generator` requires TypeScript compiler settings to be specified in a | ||||||
`tsconfig.json` file, so create one like this: | ||||||
|
||||||
```json tsconfig.json | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"enables defining" is awkward in the mouth. Another option that comes to mind is