1(async () => {
2 const rawResponse = await fetch('https://httpbin.org/post', {
3 method: 'POST',
4 headers: {
5 'Accept': 'application/json',
6 'Content-Type': 'application/json'
7 },
8 body: JSON.stringify({a: 1, b: 'Textual content'})
9 });
10 const content = await rawResponse.json();
11
12 console.log(content);
13})();
1fetch('https://example.com/profile', {
2 method: 'POST',
3 headers: { 'Content-Type': 'application/json' },
4 body: JSON.stringify({
5 'foo': 'bar'
6 }),
7})
8 .then((res) => res.json())
9 .then((data) => {
10 // Do some stuff ...
11 })
12 .catch((err) => console.log(err));
1fetch('https://jsonplaceholder.typicode.com/posts', {
2 method: 'POST',
3 headers: {
4 'Content-Type': 'application/json',
5 },
6 body: JSON.stringify({
7 // your expected POST request payload goes here
8 title: "My post title",
9 body: "My post content."
10 })
11})
12 .then(res => res.json())
13 .then(data => {
14 // enter you logic when the fetch is successful
15 console.log(data)
16 })
17 .catch(error => {
18 // enter your logic for when there is an error (ex. error toast)
19 console.log(error)
20 })
21