Skip to content

Commit a90466b

Browse files
committed
add fetch request
1 parent d00e21b commit a90466b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: DELETE request
3+
description: Simple request a DELETE api endpoint with a body
4+
author: kruimol
5+
tags: javascript,function,fetch,delete
6+
---
7+
8+
```js
9+
// then
10+
fetch("/api/delete" /* api endpoint */, {
11+
method: "DELETE",
12+
})
13+
.then((response) => response.text())
14+
.then((response) => {
15+
console.log(response);
16+
})
17+
.catch((error) => console.error("Error:", error));
18+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: GET request
3+
description: Simple request a GET api endpoint
4+
author: kruimol
5+
tags: javascript,function,fetch,get
6+
---
7+
8+
```js
9+
// then
10+
fetch("/api/get" /* api endpoint */)
11+
.then((response) => {
12+
console.log(response);
13+
})
14+
.catch((error) => console.error("Error:", error));
15+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: POST request
3+
description: Simple request a POST api endpoint with a body
4+
author: kruimol
5+
tags: javascript,function,fetch,post
6+
---
7+
8+
```js
9+
// then
10+
fetch("/api/post" /* api endpoint */, {
11+
method: "POST",
12+
headers: {
13+
"Content-Type": "application/json",
14+
},
15+
body: JSON.stringify({ a: 1, b: "Textual content" })
16+
})
17+
.then((response) => response.json())
18+
.then((response) => {
19+
console.log(response);
20+
})
21+
.catch((error) => console.error("Error:", error));
22+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: PUT request
3+
description: Simple request a PUT api endpoint with a body
4+
author: kruimol
5+
tags: javascript,function,fetch,put
6+
---
7+
8+
```js
9+
// then
10+
fetch("/api/PUT" /* api endpoint */, {
11+
method: "PUT",
12+
headers: {
13+
"Content-Type": "application/json",
14+
},
15+
body: JSON.stringify({ a: 1, b: "Textual content" })
16+
})
17+
.then((response) => response.json())
18+
.then((response) => {
19+
console.log(response);
20+
})
21+
.catch((error) => console.error("Error:", error));
22+
```

0 commit comments

Comments
 (0)