Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

> 📘
Expand Down
13 changes: 12 additions & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}!`);
});
```