From dab8cdcfb1a61c263d39834f018e038de5dda306 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Tue, 17 Jan 2023 18:51:16 -0500 Subject: [PATCH 1/2] docs: adds ESM usage instructions --- docs/usage.md | 11 +++++++++++ packages/api/README.md | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/usage.md b/docs/usage.md index b40682ec..e2e6a37a 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -28,6 +28,17 @@ petstore.listPets().then(({ data, status, headers, res }) => { }); ``` +Alternatively, you can use the ESM syntax: + +```js +import api from 'api'; +const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8'); + +petstore.listPets().then(({ data, status, headers, res }) => { + console.log(`My pets name is ${data[0].name}!`); +}); +``` + And if you use an IDE with TypeScript support (like [Visual Studio Code](https://code.visualstudio.com/)), you get the benefit of having autogenerated TypeScript types to help you out—regardless if you're actually using TypeScript! ![TypeScript types in action](https://raw.githubusercontent.com/readmeio/api/main/docs/images/ts-types.png) diff --git a/packages/api/README.md b/packages/api/README.md index b54bc60d..6b59d18c 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -43,7 +43,18 @@ const petstore = require('api')( 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json' ); -petstore.listPets().then(({ data })) => { +petstore.listPets().then(({ data }) => { + console.log(`My pets name is ${data[0].name}!`); +}); +``` + +The ESM syntax is supported as well: + +```js +import api from 'api'; +const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8'); + +petstore.listPets().then(({ data }) => { console.log(`My pets name is ${data[0].name}!`); }); ``` From 452dcec932e9ebd033a498e36be3bfb50b8790f5 Mon Sep 17 00:00:00 2001 From: Aaron Meese Date: Thu, 19 Jan 2023 00:55:54 +0000 Subject: [PATCH 2/2] fix: moves ESM syntax to "Dynamically" section --- docs/usage.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index e2e6a37a..0c719821 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -28,17 +28,6 @@ petstore.listPets().then(({ data, status, headers, res }) => { }); ``` -Alternatively, you can use the ESM syntax: - -```js -import api from 'api'; -const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8'); - -petstore.listPets().then(({ data, status, headers, res }) => { - console.log(`My pets name is ${data[0].name}!`); -}); -``` - And if you use an IDE with TypeScript support (like [Visual Studio Code](https://code.visualstudio.com/)), you get the benefit of having autogenerated TypeScript types to help you out—regardless if you're actually using TypeScript! ![TypeScript types in action](https://raw.githubusercontent.com/readmeio/api/main/docs/images/ts-types.png) @@ -55,6 +44,17 @@ petstore.listPets().then(({ data, status, headers, res }) => { }); ``` +Alternatively, you can use the ESM syntax: + +```js +import api from 'api'; +const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8'); + +petstore.listPets().then(({ data, status, headers, res }) => { + console.log(`My pets name is ${data[0].name}!`); +}); +``` + The OpenAPI definition is automatically downloaded, cached, and transformed into a chainable [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) Promise that you can use to make API requests. > 📘