|
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 | | -- [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> |
25 | 9 |
|
26 | | -### .headers ⇒ <code>Record.<string, string></code> |
| 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> |
27 | 24 |
|
28 | | -<p>Get the headers for the request</p> |
| 25 | +<a name="ApiInstance+headers"></a> |
29 | 26 |
|
30 | | -**Returns**: <code>Record.<string, string></code> <p>The headers for the request</p> |
| 27 | +### .headers ⇒ <code>Record.<string, string></code> |
| 28 | +<p>Get the headers for the request</p> |
31 | 29 |
|
32 | | -<a name='ApiInstance+config'></a> |
| 30 | +**Returns**: <code>Record.<string, string></code> <p>The headers for the request</p> |
| 31 | +<a name="ApiInstance+config"></a> |
33 | 32 |
|
34 | 33 | ### .config ⇒ <code>Record.<string, any></code> |
35 | | - |
36 | 34 | <p>The configuration of this api</p> |
37 | 35 |
|
38 | | -**Returns**: <code>Record.<string, any></code> <p>The configuration of this api</p> |
39 | | - |
40 | | -<a name='ApiInstance+makeRequest'></a> |
| 36 | +**Returns**: <code>Record.<string, any></code> <p>The configuration of this api</p> |
| 37 | +<a name="ApiInstance+makeRequest"></a> |
41 | 38 |
|
42 | 39 | ### .makeRequest(path, options) |
43 | | - |
44 | 40 | <p>Send a request to the server</p> |
45 | 41 |
|
46 | | -| Param | |
47 | | -| ------- | |
48 | | -| path | |
49 | | -| options | |
50 | 42 |
|
51 | | -<a name='ApiInstance+send'></a> |
| 43 | +| Param | |
| 44 | +| --- | |
| 45 | +| path | |
| 46 | +| options | |
52 | 47 |
|
53 | | -### .send(path, options) |
| 48 | +<a name="ApiInstance+send"></a> |
54 | 49 |
|
| 50 | +### .send(path, options) |
55 | 51 | <p>Do some pre-send stuff</p> |
56 | 52 |
|
57 | | -| Param | |
58 | | -| ------- | |
59 | | -| path | |
60 | | -| options | |
61 | 53 |
|
62 | | -<a name='ApiInstance+options'></a> |
| 54 | +| Param | |
| 55 | +| --- | |
| 56 | +| path | |
| 57 | +| options | |
63 | 58 |
|
64 | | -### .options(options, overwrite) ⇒ <code>this</code> |
| 59 | +<a name="ApiInstance+options"></a> |
65 | 60 |
|
| 61 | +### .options(options, overwrite) ⇒ <code>this</code> |
66 | 62 | <p>Set the configuration options for fetch</p> |
67 | 63 |
|
68 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 64 | +**Returns**: <code>this</code> <p>The current instance</p> |
69 | 65 |
|
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> | |
| 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> | |
74 | 70 |
|
75 | | -<a name='ApiInstance+get'></a> |
| 71 | +<a name="ApiInstance+get"></a> |
76 | 72 |
|
77 | 73 | ### .get(path, query) |
78 | | - |
79 | 74 | <p>Send a get request</p> |
80 | 75 |
|
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> | |
85 | 76 |
|
86 | | -<a name='ApiInstance+post'></a> |
| 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> | |
87 | 81 |
|
88 | | -### .post(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
| 82 | +<a name="ApiInstance+post"></a> |
89 | 83 |
|
| 84 | +### .post(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
90 | 85 | <p>Send a post request</p> |
91 | 86 |
|
92 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 87 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
93 | 88 |
|
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> | |
| 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> | |
98 | 93 |
|
99 | | -<a name='ApiInstance+put'></a> |
| 94 | +<a name="ApiInstance+put"></a> |
100 | 95 |
|
101 | 96 | ### .put(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
102 | | - |
103 | 97 | <p>Send a put request</p> |
104 | 98 |
|
105 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 99 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
106 | 100 |
|
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> | |
| 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> | |
111 | 105 |
|
112 | | -<a name='ApiInstance+delete'></a> |
| 106 | +<a name="ApiInstance+delete"></a> |
113 | 107 |
|
114 | 108 | ### .delete(path) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
115 | | - |
116 | 109 | <p>Send a delete request</p> |
117 | 110 |
|
118 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 111 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
119 | 112 |
|
120 | | -| Param | Type | Description | |
121 | | -| ----- | ------------------- | ------------------------------------- | |
122 | | -| path | <code>string</code> | <p>The url to send the request to</p> | |
| 113 | +| Param | Type | Description | |
| 114 | +| --- | --- | --- | |
| 115 | +| path | <code>string</code> | <p>The url to send the request to</p> | |
123 | 116 |
|
124 | | -<a name='ApiInstance+patch'></a> |
| 117 | +<a name="ApiInstance+patch"></a> |
125 | 118 |
|
126 | 119 | ### .patch(path, body) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
127 | | - |
128 | 120 | <p>Send a patch request</p> |
129 | 121 |
|
130 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 122 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
131 | 123 |
|
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> | |
| 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> | |
136 | 128 |
|
137 | | -<a name='ApiInstance+gql'></a> |
| 129 | +<a name="ApiInstance+gql"></a> |
138 | 130 |
|
139 | 131 | ### .gql(query, variables) ⇒ <code>Promise.<PlexusApiRes.<unknown>></code> |
140 | | - |
141 | 132 | <p>Send a graphql request</p> |
142 | 133 |
|
143 | | -**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
| 134 | +**Returns**: <code>Promise.<PlexusApiRes.<unknown>></code> <p>The response from the server</p> |
144 | 135 |
|
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> | |
| 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> | |
149 | 140 |
|
150 | | -<a name='ApiInstance+auth'></a> |
| 141 | +<a name="ApiInstance+auth"></a> |
151 | 142 |
|
152 | 143 | ### .auth(type, token) ⇒ <code>this</code> |
153 | | - |
154 | 144 | <p>Set the authentication details for the request</p> |
155 | 145 |
|
156 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 146 | +**Returns**: <code>this</code> <p>The current instance</p> |
157 | 147 |
|
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> | |
| 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> | |
162 | 152 |
|
163 | | -<a name='ApiInstance+reset'></a> |
| 153 | +<a name="ApiInstance+reset"></a> |
164 | 154 |
|
165 | 155 | ### .reset() ⇒ <code>this</code> |
166 | | - |
167 | 156 | <p>Reset this routes configuration</p> |
168 | 157 |
|
169 | | -**Returns**: <code>this</code> <p>The current instance</p> |
| 158 | +**Returns**: <code>this</code> <p>The current instance</p> |
0 commit comments