Skip to content

Commit 6fadba7

Browse files
authored
Adds ESM usage instructions (#606)
* docs: adds ESM usage instructions * fix: moves ESM syntax to "Dynamically" section
1 parent 33d0a4e commit 6fadba7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

docs/usage.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ petstore.listPets().then(({ data, status, headers, res }) => {
4444
});
4545
```
4646

47+
Alternatively, you can use the ESM syntax:
48+
49+
```js
50+
import api from 'api';
51+
const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
52+
53+
petstore.listPets().then(({ data, status, headers, res }) => {
54+
console.log(`My pets name is ${data[0].name}!`);
55+
});
56+
```
57+
4758
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.
4859

4960
> 📘

packages/api/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ const petstore = require('api')(
4343
'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json'
4444
);
4545

46-
petstore.listPets().then(({ data })) => {
46+
petstore.listPets().then(({ data }) => {
47+
console.log(`My pets name is ${data[0].name}!`);
48+
});
49+
```
50+
51+
The ESM syntax is supported as well:
52+
53+
```js
54+
import api from 'api';
55+
const petstore = api('@petstore/v1.0#tl1e4kl1cl8eg8');
56+
57+
petstore.listPets().then(({ data }) => {
4758
console.log(`My pets name is ${data[0].name}!`);
4859
});
4960
```

0 commit comments

Comments
 (0)