|
1 | | ---- |
2 | | - title: ApiInstance |
3 | | ---- |
| 1 | +--- |
| 2 | +title: ApiInstance |
| 3 | +--- |
4 | 4 |
|
5 | 5 | [](https://www.npmjs.org/package/@plexusjs/core) |
6 | 6 |
|
7 | 7 | An API instance is used to make requests to a server. Interact with this by using api() |
8 | 8 |
|
9 | | - |
10 | | -* [ApiInstance](#ApiInstance) |
11 | | - * [.headers](#ApiInstance+headers) ⇒ <code>Record.<string, string></code> |
12 | | - * [.config](#ApiInstance+config) ⇒ <code>Record.<string, any></code> |
13 | | - * [.makeRequest(path, options)](#ApiInstance+makeRequest) |
14 | | - * [.send(path, options)](#ApiInstance+send) |
15 | | - * [.options(options, overwrite)](#ApiInstance+options) ⇒ <code>this</code> |
16 | | - * [.get(path, query)](#ApiInstance+get) |
17 | | - * [.post(path, body)](#ApiInstance+post) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
18 | | - * [.put(path, body)](#ApiInstance+put) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
19 | | - * [.delete(path)](#ApiInstance+delete) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
20 | | - * [.patch(path, body)](#ApiInstance+patch) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
21 | | - * [.gql(query, variables)](#ApiInstance+gql) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
22 | | - * [.auth(type, token)](#ApiInstance+auth) ⇒ <code>this</code> |
23 | | - * [.reset()](#ApiInstance+reset) ⇒ <code>this</code> |
24 | | - |
25 | | -<a name="ApiInstance+headers"></a> |
| 9 | +- [ApiInstance](#ApiInstance) |
| 10 | + - [.headers](#ApiInstance+headers) ⇒ <code>Record.<string, string></code> |
| 11 | + - [.config](#ApiInstance+config) ⇒ <code>Record.<string, any></code> |
| 12 | + - [.makeRequest(path, options)](#ApiInstance+makeRequest) |
| 13 | + - [.send(path, options)](#ApiInstance+send) |
| 14 | + - [.options(options, overwrite)](#ApiInstance+options) ⇒ <code>this</code> |
| 15 | + - [.get(path, query)](#ApiInstance+get) |
| 16 | + - [.post(path, body)](#ApiInstance+post) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 17 | + - [.put(path, body)](#ApiInstance+put) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 18 | + - [.delete(path)](#ApiInstance+delete) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 19 | + - [.patch(path, body)](#ApiInstance+patch) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 20 | + - [.gql(query, variables)](#ApiInstance+gql) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 21 | + - [.auth(type, token)](#ApiInstance+auth) ⇒ <code>this</code> |
| 22 | + - [.reset()](#ApiInstance+reset) ⇒ <code>this</code> |
| 23 | + |
| 24 | +<a name='ApiInstance+headers'></a> |
26 | 25 |
|
27 | 26 | ### .headers ⇒ <code>Record.<string, string></code> |
| 27 | + |
28 | 28 | <p>Get the headers for the request</p> |
29 | 29 |
|
30 | | -**Returns**: <code>Record.<string, string></code> <p>The headers for the request</p> |
31 | | -<a name="ApiInstance+config"></a> |
| 30 | +**Returns**: <code>Record.<string, string></code> <p>The headers for the request</p> |
| 31 | + |
| 32 | +<a name='ApiInstance+config'></a> |
32 | 33 |
|
33 | 34 | ### .config ⇒ <code>Record.<string, any></code> |
| 35 | + |
34 | 36 | <p>The configuration of this api</p> |
35 | 37 |
|
36 | | -**Returns**: <code>Record.<string, any></code> <p>The configuration of this api</p> |
37 | | -<a name="ApiInstance+makeRequest"></a> |
| 38 | +**Returns**: <code>Record.<string, any></code> <p>The configuration of this api</p> |
| 39 | + |
| 40 | +<a name='ApiInstance+makeRequest'></a> |
38 | 41 |
|
39 | 42 | ### .makeRequest(path, options) |
40 | | -<p>Send a request to the server</p> |
41 | 43 |
|
| 44 | +<p>Send a request to the server</p> |
42 | 45 |
|
43 | | -| Param | |
44 | | -| --- | |
45 | | -| path | |
46 | | -| options | |
| 46 | +| Param | |
| 47 | +| ------- | |
| 48 | +| path | |
| 49 | +| options | |
47 | 50 |
|
48 | | -<a name="ApiInstance+send"></a> |
| 51 | +<a name='ApiInstance+send'></a> |
49 | 52 |
|
50 | 53 | ### .send(path, options) |
51 | | -<p>Do some pre-send stuff</p> |
52 | 54 |
|
| 55 | +<p>Do some pre-send stuff</p> |
53 | 56 |
|
54 | | -| Param | |
55 | | -| --- | |
56 | | -| path | |
57 | | -| options | |
| 57 | +| Param | |
| 58 | +| ------- | |
| 59 | +| path | |
| 60 | +| options | |
58 | 61 |
|
59 | | -<a name="ApiInstance+options"></a> |
| 62 | +<a name='ApiInstance+options'></a> |
60 | 63 |
|
61 | 64 | ### .options(options, overwrite) ⇒ <code>this</code> |
| 65 | + |
62 | 66 | <p>Set the configuration options for fetch</p> |
63 | 67 |
|
64 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 68 | +**Returns**: <code>this</code> <p>The current instance</p> |
65 | 69 |
|
66 | | -| Param | Type | Default | Description | |
67 | | -| --- | --- | --- | --- | |
68 | | -| options | <code>RequestInit</code> | | <p>Same as fetch options</p> | |
69 | | -| overwrite | <code>boolean</code> | <code>false</code> | <p>(optional) If true, will overwrite the current options object</p> | |
| 70 | +| Param | Type | Default | Description | |
| 71 | +| --------- | ------------------------ | ------------------ | -------------------------------------------------------------------- | |
| 72 | +| options | <code>RequestInit</code> | | <p>Same as fetch options</p> | |
| 73 | +| overwrite | <code>boolean</code> | <code>false</code> | <p>(optional) If true, will overwrite the current options object</p> | |
70 | 74 |
|
71 | | -<a name="ApiInstance+get"></a> |
| 75 | +<a name='ApiInstance+get'></a> |
72 | 76 |
|
73 | 77 | ### .get(path, query) |
74 | | -<p>Send a get request</p> |
75 | 78 |
|
| 79 | +<p>Send a get request</p> |
76 | 80 |
|
77 | | -| Param | Type | Description | |
78 | | -| --- | --- | --- | |
79 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
80 | | -| query | <code>Record.<string, any></code> | <p>The url query to send</p> | |
| 81 | +| Param | Type | Description | |
| 82 | +| ----- | --------------------------------------- | ------------------------------------- | |
| 83 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
| 84 | +| query | <code>Record.<string, any></code> | <p>The url query to send</p> | |
81 | 85 |
|
82 | | -<a name="ApiInstance+post"></a> |
| 86 | +<a name='ApiInstance+post'></a> |
83 | 87 |
|
84 | 88 | ### .post(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 89 | + |
85 | 90 | <p>Send a post request</p> |
86 | 91 |
|
87 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 92 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
88 | 93 |
|
89 | | -| Param | Type | Description | |
90 | | -| --- | --- | --- | |
91 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
92 | | -| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
| 94 | +| Param | Type | Description | |
| 95 | +| ----- | -------------------------------------------------------------- | ---------------------------------------------------------- | |
| 96 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
| 97 | +| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
93 | 98 |
|
94 | | -<a name="ApiInstance+put"></a> |
| 99 | +<a name='ApiInstance+put'></a> |
95 | 100 |
|
96 | 101 | ### .put(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 102 | + |
97 | 103 | <p>Send a put request</p> |
98 | 104 |
|
99 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 105 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
100 | 106 |
|
101 | | -| Param | Type | Description | |
102 | | -| --- | --- | --- | |
103 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
104 | | -| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
| 107 | +| Param | Type | Description | |
| 108 | +| ----- | -------------------------------------------------------------- | ---------------------------------------------------------- | |
| 109 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
| 110 | +| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
105 | 111 |
|
106 | | -<a name="ApiInstance+delete"></a> |
| 112 | +<a name='ApiInstance+delete'></a> |
107 | 113 |
|
108 | 114 | ### .delete(path) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 115 | + |
109 | 116 | <p>Send a delete request</p> |
110 | 117 |
|
111 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 118 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
112 | 119 |
|
113 | | -| Param | Type | Description | |
114 | | -| --- | --- | --- | |
115 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
| 120 | +| Param | Type | Description | |
| 121 | +| ----- | ------------------- | ------------------------------------- | |
| 122 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
116 | 123 |
|
117 | | -<a name="ApiInstance+patch"></a> |
| 124 | +<a name='ApiInstance+patch'></a> |
118 | 125 |
|
119 | 126 | ### .patch(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 127 | + |
120 | 128 | <p>Send a patch request</p> |
121 | 129 |
|
122 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 130 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
123 | 131 |
|
124 | | -| Param | Type | Description | |
125 | | -| --- | --- | --- | |
126 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
127 | | -| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
| 132 | +| Param | Type | Description | |
| 133 | +| ----- | -------------------------------------------------------------- | ---------------------------------------------------------- | |
| 134 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
| 135 | +| body | <code>Record.<string, any></code> \| <code>string</code> | <p>The body of the request (can be a string or object)</p> | |
128 | 136 |
|
129 | | -<a name="ApiInstance+gql"></a> |
| 137 | +<a name='ApiInstance+gql'></a> |
130 | 138 |
|
131 | 139 | ### .gql(query, variables) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 140 | + |
132 | 141 | <p>Send a graphql request</p> |
133 | 142 |
|
134 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 143 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
135 | 144 |
|
136 | | -| Param | Type | Description | |
137 | | -| --- | --- | --- | |
138 | | -| query | <code>string</code> | <p>The gql query to send</p> | |
139 | | -| variables | <code>Record.<string, any></code> | <p>Variables</p> | |
| 145 | +| Param | Type | Description | |
| 146 | +| --------- | --------------------------------------- | ---------------------------- | |
| 147 | +| query | <code>string</code> | <p>The gql query to send</p> | |
| 148 | +| variables | <code>Record.<string, any></code> | <p>Variables</p> | |
140 | 149 |
|
141 | | -<a name="ApiInstance+auth"></a> |
| 150 | +<a name='ApiInstance+auth'></a> |
142 | 151 |
|
143 | 152 | ### .auth(type, token) ⇒ <code>this</code> |
| 153 | + |
144 | 154 | <p>Set the authentication details for the request</p> |
145 | 155 |
|
146 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 156 | +**Returns**: <code>this</code> <p>The current instance</p> |
147 | 157 |
|
148 | | -| Param | Type | Description | |
149 | | -| --- | --- | --- | |
150 | | -| type | <code>'bearer'</code> \| <code>'basic'</code> \| <code>'jwt'</code> | <p>optional - The type of authentication to use. This determines what prefix to use for the header</p> | |
151 | | -| token | <code>string</code> | <p>The token to use for authentication</p> | |
| 158 | +| Param | Type | Description | |
| 159 | +| ----- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | |
| 160 | +| type | <code>'bearer'</code> \| <code>'basic'</code> \| <code>'jwt'</code> | <p>optional - The type of authentication to use. This determines what prefix to use for the header</p> | |
| 161 | +| token | <code>string</code> | <p>The token to use for authentication</p> | |
152 | 162 |
|
153 | | -<a name="ApiInstance+reset"></a> |
| 163 | +<a name='ApiInstance+reset'></a> |
154 | 164 |
|
155 | 165 | ### .reset() ⇒ <code>this</code> |
| 166 | + |
156 | 167 | <p>Reset this routes configuration</p> |
157 | 168 |
|
158 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 169 | +**Returns**: <code>this</code> <p>The current instance</p> |
0 commit comments