You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
A Netlify [open-api](https://github.com/netlify/open-api) client that works in the browser and Node.js.
6
+
A Netlify [OpenAPI](https://github.com/netlify/open-api) client that works in the browser and Node.js.
7
7
8
8
## Usage
9
9
@@ -13,7 +13,7 @@ const client = new NetlifyAPI('1234myAccessToken')
13
13
constsites=awaitclient.listSites()
14
14
```
15
15
16
-
## Using Open API operations
16
+
## Using OpenAPI operations
17
17
18
18
```js
19
19
constNetlifyAPI=require('netlify')
@@ -52,8 +52,9 @@ Create a new instance of the Netlify API client with the provided `accessToken`.
52
52
scheme:'https',
53
53
host:'api.netlify.com',
54
54
pathPrefix:'/api/v1',
55
+
accessToken:'1234myAccessToken',
55
56
globalParams: {} // parameters you want available for every request.
56
-
// Global params are only sent of the open-api spec specifies the provided params.
57
+
// Global params are only sent of the OpenAPI spec specifies the provided params.
57
58
}
58
59
```
59
60
@@ -65,19 +66,19 @@ A setter/getter that returns the `accessToken` that the client is configured to
65
66
66
67
A getter that returns the formatted base URL of the endpoint the client is configured to use.
67
68
68
-
### Open API Client methods
69
+
### OpenAPI Client methods
69
70
70
-
The client is dynamically generated from the [open-api](https://github.com/netlify/open-api) definition file. Each method is is named after the `operationId` name of each operation. **To see list of available operationssee the [open-api website](https://open-api.netlify.com/)**.
71
+
The client is dynamically generated from the [OpenAPI](https://github.com/netlify/open-api) definition file. Each method is is named after the `operationId` name of each operation. **To see a list of available operations, please see the [OpenAPI website](https://open-api.netlify.com/)**.
71
72
72
-
Every open-api operation has the following signature:
73
+
Every OpenAPI operation has the following signature:
Perform a call to the given endpoint corresponding with the `operationId`. Returns promise that will resolve with the body of the response, or reject with an error with details about the request attached. Rejects if the `status` > 400.
77
+
Performs a call to the given endpoint corresponding with the `operationId`. Returns a promise resolved with the body of the response, or rejected with an error with the details about the request attached. Rejects if the `status` > 400.
77
78
78
79
-`params` is an object that includes any of the required or optional endpoint parameters.
79
-
-`params.body` should be an object which gets serialized to JSON automatically. Any object can live here but refer to the open-api specification for allowed fields in a particular request body.
80
-
- If the endpoint accepts `binary`, `params.body` can be a Node.js readable stream or stream ctor (e.g. `() => fs.createReadStream('./foo')`). A Stream ctor function is required to support rate limit retry.
80
+
-`params.body` should be an object which gets serialized to JSON automatically. Any object can live here but refer to the OpenAPI specification for allowed fields in a particular request body. It can also be a function returning an object.
81
+
- If the endpoint accepts `binary`, `params.body` can be a Node.js readable stream or a function returning one (e.g. `() => fs.createReadStream('./foo')`). Using a function is recommended.
81
82
82
83
```js
83
84
// example params
@@ -90,7 +91,7 @@ Perform a call to the given endpoint corresponding with the `operationId`. Retur
90
91
}
91
92
```
92
93
93
-
Optional `opts` can include any property you want passed to `node-fetch`. The `headers` property is merged with some `defaultHeaders`.
94
+
Optional `opts` can include any property you want passed to [`node-fetch`](https://github.com/bitinn/node-fetch). The `headers` property is merged with some `defaultHeaders`.
94
95
95
96
```js
96
97
// example opts
@@ -119,13 +120,13 @@ async function getSomeData() {
119
120
}
120
121
```
121
122
122
-
If the request response includes `json` in the `contentType` header, fetch will deserialize the JSON body. Otherwise the `text` of the response is returned.
123
+
If the response includes `json` in the `contentType` header, fetch will deserialize the JSON body. Otherwise the `text` of the response is returned.
123
124
124
125
### API Flow Methods
125
126
126
127
Some methods have been added in addition to the open API operations that make certain actions simpler to perform.
Pass in a [`ticket`](https://open-api.netlify.com/#model-ticket) and get back an `accessToken`. Call this with the response from a `client.createTicket({ client_id })` call. Automatically sets the `accessToken` to `this.accessToken` and returns `accessToken` for the consumer to save for later.
0 commit comments