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 Feb 12, 2026. It is now read-only.
Fitch.js allows you to use a custom configuration for your requests. You just need to pass a config object as second parameter of the Fitch.js methods.
4
+
5
+
## Objects available
6
+
7
+
**body**
8
+
9
+
Receives a json object, that is transformed to string by Fitch.js, before send the request.
10
+
11
+
**Note:** GET method doesn't allow `body` inside config object.
12
+
13
+
```js
14
+
constreq= { body: { name:'Happy cat' } }
15
+
16
+
fitch.post(apiUrl, req)
17
+
.then(data=>console.log(data))
18
+
```
19
+
20
+
**cache**
21
+
22
+
Same as in Fetch API. [See more at MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request/cache).
23
+
24
+
**headers**
25
+
26
+
Same as in Fetch API. [See more at MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request/headers).
27
+
28
+
**mode**
29
+
30
+
Same as in Fetch API. [See more at MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode).
31
+
32
+
**params**
33
+
34
+
You don't need to pass your URL parameters as string. Fitch.js allows you to pass the parameters inside a object:
35
+
36
+
```js
37
+
constconfig= {
38
+
params: { // transform to '?test1=test-1&test2=test-2'
39
+
test1:'test-1',
40
+
test2:'test-2',
41
+
},
42
+
}
43
+
44
+
fitch.get(apiUrl, config)
45
+
.then(data=>console.log(data))
46
+
```
47
+
48
+
**raw**
49
+
50
+
Returns the raw output of Fetch API, so you can work with headers and custom requests like files.
**Note:** GET method doesn't allow `body` inside config object.
11
+
12
+
**post(url, config)**
13
+
14
+
```js
15
+
constreq= { body: { name:'Happy cat' } }
16
+
17
+
fitch.post(apiUrl, req)
18
+
.then(data=>console.log(data))
19
+
```
20
+
21
+
**put(url, config)**
22
+
23
+
```js
24
+
constreq= { body: { name:'Happy cat' } }
25
+
26
+
fitch.put(apiUrl, req)
27
+
.then(data=>console.log(data))
28
+
```
29
+
30
+
**patch(url, config)**
31
+
32
+
```js
33
+
constreq= { body: { name:'Happy cat' } }
34
+
35
+
fitch.patch(apiUrl, req)
36
+
.then(data=>console.log(data))
37
+
```
38
+
39
+
**delete(url, config)**
40
+
41
+
```js
42
+
fitch.delete(apiUrl)
43
+
.then(data=>console.log(data))
44
+
```
45
+
46
+
## Handling errors
47
+
If Fetch throws an error, we can handle this using `catch()`:
48
+
49
+
```js
50
+
fitch.get(apiUrl)
51
+
.then(data=>console.log(data))
52
+
.catch(fitch.error) // log the error message on the console
53
+
```
54
+
55
+
**Note:** Fitch.js allows you to use a custom configuration for your requests. [You can learn about it here](https://github.com/raphaelpor/fitch.js/blob/master/docs/Config.md).
0 commit comments