Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Commit d7c546a

Browse files
committed
Much better Route Docs
1 parent cbdd6a1 commit d7c546a

File tree

1 file changed

+23
-102
lines changed

1 file changed

+23
-102
lines changed

docs/v4/docs/route.md

Lines changed: 23 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,46 @@
22
title: Route
33
---
44
## Introduction
5-
::: warning Sorry!
6-
This page is not up to standards, improvements need to be made inline with the rest of the documentation.
7-
:::
5+
86
# Route
97

108
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-
```
149
## 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!
1611
```ts
17-
const MyAPI = App.API({
12+
const MyAPI = route({
13+
baseURL: 'http://localhost:3000', // default: 'https://localhost'
1814
options: {
1915
headers: {
20-
'content-type': 'application/json, text/plain' // this is not necessary
16+
'Content-Type': 'application/json'
2117
}
2218
},
23-
baseURL: 'https://api.mysite.co', // default: 'https://localhost'
24-
path: '/api', // default: '/'
2519
timeout: 20000, // default: infinite
26-
requestIntercept: request => {
27-
// do something
20+
})
21+
```
22+
## Use
23+
The returned function accepts a path, and another opportunity to modify the fetch config.
24+
```ts
25+
const data = await MyAPI('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+
}
2836
},
29-
responseIntercept: response => {
30-
// do something
31-
}
3237
});
3338
```
3439

35-
### API Config Parameters
40+
### Route Config Parameters
3641

3742
- [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
3843
- [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
4044
- [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
4345

4446
### Request Options
4547

@@ -54,7 +56,7 @@ const MyAPI = App.API({
5456
- [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).
5557

5658
::: 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.
5860
:::
5961

6062
### Response
@@ -71,85 +73,4 @@ interface PulseResponse<DataType = any> {
7173
}
7274
```
7375

74-
## Methods
75-
76-
# `.with()`
77-
78-
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
151-
- [options (RequestOptions)]() _**optional**_ -
152-
153-
### Returns
15476

155-
- [response (Response)](#response)

0 commit comments

Comments
 (0)