showing results for - "fetch api"
Ethan
13 Apr 2020
1// This will fetch api.example.com/comments with a header and a body
2fetch(`https://api.example.com/comments`, {
3  method: 'POST', //This could be any http method
4  headers: {
5    'Authorization': 'Basic SGVsbG8gdGhlcmUgOikgSGF2ZSBhIGdvb2QgZGF5IQ==',
6    'Content-Type': 'application/json',
7  },
8  body: JSON.stringify({
9	UID: 58,
10    Comment: "Fetch is really easy!",
11  }),
12})
13.then((response) => response.json())
14.then((newComment) => {
15  // Do something magical with your newly posted comment :)
16});
Raphael
25 Mar 2020
1// Fetch and Async/Await
2
3const url = 'http://dummy.restapiexample.com/api/v1/employees'; 
4const fetchUsers = async () => {
5    try {
6       const res = await fetch(url);
7     // check for 404 error
8       if (!res.ok) { 
9           throw new Error(res.status);
10       }
11       const data = await res.json();
12          console.log(data);
13       }
14       // catch block for network errors
15       catch (error) { 
16            console.log(error); 
17        }
18}
19fetchUsers( );
Sofie
10 Aug 2018
1// Error handling while fetching API
2
3const url = "http://dummy.restapiexample.com/api/v1/employee/40";
4fetch(url) //404 error
5     .then( res => {
6          if (res.ok) {
7                return res.json( );
8          } else {
9                return Promise.reject(res.status); 
10           }
11      })
12      .then(res => console.log(res))
13      .catch(err => console.log('Error with message: ${err}') ); 
Mathilda
17 Oct 2019
1// Making get requests
2
3const url = "http://dummy.restapiexample.com/api/v1/employees"; 
4fetchurl()
5     .then(res => {
6            console.log(res);
7})
8      .catch(err => {
9             console.log('Error: ${err}' ); 
10});
Betsy
31 Apr 2020
1fetch('http://example.com/movies.json')
2  .then(response => response.json())
3  .then(data => console.log(data));
4
Marlon
24 Jun 2019
1// Making post request
2
3const url = 'http://dummy.restapiexample.com/api/v1/create'
4const user = {
5      name: 'Rahul'
6      age: '16'
7      salary: '000'
8};
9
10const options = {
11   method: 'POST'
12   body: JSON.stringify(user), 
13}
14
15fetch(url, options)
16     .then( res => res.json())
17     .then( res=> console.log(res));
queries leading to this page
fetch api method getapi get fetchfetch meaningresponse from fetch post promiseusing fetch apifetch an api javascriptfetch javascript apiwhat does javascript fetch dofetch api get requestjavascript execute fetch in serieswhat does the fetch method returnfetch 28 29 apiapi fetch in jsfetch apiomozilla docs fetchfetch 28fetch jsdwhat does fetch function dofetch example jsfetch 2fdefining fetch apiis fetch api for working with apiswaht is fetch apifetch api search functionhtml5 fetch supportfetch response jswhy can 27t i use fetch apiapi fetch methods jswhat is fetch api meanfetch 2fapi 2ffetch javascript reasponsefetch kaylefetch for api callsjs fetch apijavascript fetch get examplemdn fetch api javascripitfetch request rest apifetch 28 29what is fetch jsrest api javascript fetchfetch get requestfetch with jswhat is window fetchfetch api 29fetch call apiwhat is fetch apifetch 2fjavascript fetch apihttp type fetchfetch api get request jsusing fetch mdnfetching apifetch request javascriptfetch api in jsfetch apu 27browser fetch apijavascript fetch thenfetch in javascriptwhats fetch apijavascript fetch headers enable adsfetch request apiis fetch an apijavascript fetch examplefetch mdnfetch responsefetch definitionreturn value from fetchfetch api ahentfetch api nedirfetch function jsfetch method getfetch api introfetch resclient fetchfetch methodjs request fetchmethod fetchfetch web apifetch apjavascript fetch methodfetch requestfetch api jsfetch apiwhat is fetch in jsjavascript notify fetchfetch 28 29 jafetch explainedfecth in javascriptfetching from apijavascript fetch libraryfetch meansfetch with get requestfetch response from apifetch api libraryapi fetch how tojs fetch tutorialfetch api in javascriptfetch api usin javascriptfetch jsfetching an api in jsjavascript fetch apifetch apireact fetchwindows fetchjs fetch requestwhat is fetchfetch api smdn fetchmozilla doc fetchapi fetchjs fetch ie fetch javascriptfetch javascripthttp vs fetcgfetch rest mdnwhat is the fetch api used for 3ftype opaque responsejs fetch getwhat does fetch dofetch techniquesfetch 2f 2fset get fetchjavascript fetch 28 29fetch api thenfetch api examplefetch api callfetch api implementationjavascript fetch for the apifetching an api javascriptfetch javascript meaningfetch api supportdefine fetchfetch in jsfetch api from jsmdn fetch apifetch get apifetchfetch functionapi request fetchfetch api ppfetch default methodjs fetch upgrade connectionfetchh api explain fetch api in javascriptfetch appfetch vshowto fetch into apifetch apifetch method 3f fetch javascript method 22fetch 22como usar a fetch api do javascriptbasic fetch apifetch javascript call apiunderstanding fetch apifetch api searchapi fetch javascriptfetch syntaxfetch api method request getjs fetch rest api fetch 28 29 jsfetch api get response fetch fetchfetch rest api javascriptfetch methodsja fetchfetch request jsapi javascript fetchfetch rest apiuse fetchfetch whoerfetch aapi js fetch in apifetch method in javascriptfetch javascriptfetch api setfetch apu 09fetch 28 29fetch mdnfetch optionsthis fetchfetch api javascript explained 24 fetchhow display fetch request on page browserjavascript fetch like requestsfetch geetis fetch dom apijs fetch from apifetch api definition javascriptjavascript fetchfetch multiorgiginjavascript fetch api tfetch browser supportfetch api explainedapi fetch callfetch an apifetch api javasciptdisplay fetch api in browserfetch 2fwhere fetch method comes fromfetch fetchfetch api javascriptjs api fetchapi fetch jsfetch tutorialcall api fetchjavascript fetch getfetch api getfetch completefetch 28 29 javascriptwhat does fetch do javascriptjava script fetchwhat is fetch 28 29fetch api fetch jsget response from post request javascript fetchfetch 28 29 api in jsfetch js getjavascript fetch rest apifetch supportwindow fetch resultmodule for fetch api javascriptthis 24fetchfetch method apifetch specific api elementsfetch 28 29fetch httpworking with fetch apiwhat does the javascript fetch function dofetch requestfecth javascriptwindow fetch mdnfetch requestsfetch en js fetch apirequest fetch jsfetch api syntaxfetch method javascriptin which fomat data is fetched from apifetch api requestjs fetch functionapi method fetchfetch get react examplefetch 27tfetch get jswhat does fetch do 3fhttp fetchfetch something apifetch api rest apifetch api javascript examplewindow fetchfetch from api javascriptfetch exampleusing fetcg jsjs fetchapilibrary for fetch jsfunction fetch apihow to fetch apifetch 27fetch api xmlfetch domjavascript browser fetchfetch 28 60 22fetch api 22fetch method jsfetch 28 29 jsrest api 2b fetchfetch javasce javascript fetchfetch apisfetch callfetch js functionsfetch api demofetch getget response fetchfetch apihttp fetch jswhat is fetch api in javascriptget vs fetch javascriptfetch what it iswhat does fetch javascript dofetchjs responsehow to use fetch api result in global scopefetch with xml apifetch nedirrest api fetchmeaning of fetchhow to fetch informationjs fetchfetch api clientfetch api structurethe fetchhaderes for fetchfetch api mdnfetch js responsefetch wefetching from a web apifetch api exampleswhat is fetch javascriptfetch withfetch api