diff --git a/docs/usage.md b/docs/usage.md index b40682ec..0c719821 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -44,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. > 📘 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}!`); }); ```