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 1, 2022. It is now read-only.
This page is not up to standards, improvements need to be made inline with the rest of the documentation.
7
-
:::
5
+
8
6
# Route
9
7
10
8
This is Pulse's integrated fetch API. It's a wrapper around Fetch, which is native to the browser environment.
11
-
```ts
12
-
const MyAPI =route()
13
-
```
14
9
## Setup
15
-
The API class accepts a config object.
10
+
The route function returns a __Route__ which can be configured and used to make HTTP requests. The basic config is just the baseurl and any fetch config options. There is also a value for timeout, which will set a timeout for the request. This function will return another function to use to make requests in your actions or anywhere else in your app!
The returned function accepts a path, and another opportunity to modify the fetch config.
24
+
```ts
25
+
const data =awaitMyAPI('get-data', {
26
+
method: 'POST', // default: 'GET'
27
+
body: {
28
+
data: 'Hello World!'
29
+
},
30
+
params: {}, // url params
31
+
query: {}, // url query
32
+
options: {
33
+
headers: {
34
+
'Content-Type': 'application/json, text/plain'// this is not necessary
35
+
}
28
36
},
29
-
responseIntercept: response=> {
30
-
// do something
31
-
}
32
37
});
33
38
```
34
39
35
-
### API Config Parameters
40
+
### Route Config Parameters
36
41
37
42
-[options (RequestOptions)](#request-options)_**optional**_ - This has all the same options as the js fetch function. Nothing is required, but it is recommended depending on your setup
38
43
-[baseURL (string)]()_**optional**_ - The base url for the endpoint which defaults to your local system.
39
-
-[path (string)]()_**optional**_ - The path for the endpoint which defaults to root
40
44
-[timeout (number)]()_**optional**_ - A timeout for the fetch. By default it does not have a timeout so if you are unsure if the request will complete, you should set this.
41
-
-[requestIntercept (Function)]()_**optional**_ - An intercept function on request sent
42
-
-[responseIntercept (Function)]()_**optional**_ - An intercept function on response received
43
45
44
46
### Request Options
45
47
@@ -54,7 +56,7 @@ const MyAPI = App.API({
54
56
-[signal (AbortSignal)]()_**optional**_ - An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) object instance; allows you to communicate with a fetch request and abort it if desired via an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
55
57
56
58
::: tip Note: Refer to Fetch Documentation for More Info.
57
-
For more information on the options available, please refer to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) page, as this is what is used under the hood.
59
+
For more information on the options available, please refer to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) page, as we use this under the hood.
This function allows you to override the API config and request options. It returns a modified instance of the original API with the options in the config parameter overriding the original config options.
79
-
80
-
### Parameters
81
-
82
-
-[config (APIConfig)](#api-config-parameters)
83
-
84
-
### Returns
85
-
86
-
-[response (Response)](#response)
87
-
88
-
# `.get()`
89
-
90
-
Send a HTTP get request to a url
91
-
92
-
### Parameters
93
-
94
-
-[path (string)]() - The URL path to use
95
-
-[options (RequestOptions)]()_**optional**_ - has the same options as fetch
96
-
97
-
### Returns
98
-
99
-
-[response (Response)](#response)
100
-
101
-
# `.post()`
102
-
103
-
Send a HTTP post request to a URL
104
-
105
-
### Parameters
106
-
107
-
-[path (string)]() - The URL path to use
108
-
-[data (Object)]() - The data to send as the body of the post request
109
-
-[options (RequestOptions)]()_**optional**_ -
110
-
111
-
### Returns
112
-
113
-
-[response (Response)](#response)
114
-
115
-
# `.put()`
116
-
117
-
Send a HTTP put request to a URL
118
-
119
-
### Parameters
120
-
121
-
-[path (string)]() - The URL path to use
122
-
-[data (Object)]() - The data to send as the body of the put request
123
-
-[options (RequestOptions)]()_**optional**_ -
124
-
125
-
### Returns
126
-
127
-
-[response (Response)](#response)
128
-
129
-
# `.patch()`
130
-
131
-
Send a HTTP patch request to a URL
132
-
133
-
### Parameters
134
-
135
-
-[path (string)]() - The URL path to use
136
-
-[data (Object)]() - The data to send as the body of the patch request
137
-
-[options (RequestOptions)]()_**optional**_ -
138
-
139
-
### Returns
140
-
141
-
-[Response (response)](#response)
142
-
143
-
# `.delete()`
144
-
145
-
Send a HTTP delete request to a URL
146
-
147
-
### Parameters
148
-
149
-
-[path (string)]() - The URL path to use
150
-
-[data (Object)]() - The data to send as the body of the delete request
0 commit comments