Today's videoisgoingtobe a quickvideowhere I showyouhowtousethefetch a p I builtintothebrowserinordertomake a synchronousrequesttodifferentnetworkResourceisbyusinggetpostputwhateveritisthatyouwanttouse.
Andifwesaythatyouseethatwe'regetting a promiseonthesidehere.
Soweknowthatfetchispromisedbased, whichmeansthatwecanuse a sink a weightwherewecanusedotthenanddotcatchwithit.
Andifyou'renotfamiliarwithpromisesor a singleweight, I havelinksinthedescriptionandinthecardsthatyoucancheckoutthosevideosthat I'vemadeonbothofthosetopics.
SotogetstartedleadingtodoisweneedtosaydotFinnandfetchisgoingtoreturntous a response.
Sowehave a responseobject, andwe'regonnalogoutthatresponseobjecttoseeexactlywhatthislookslike.
Andifwesavethat, yousee, weget a responsethatsaysthatthestatuswas 200 saysstatusTexasemptyokayistrue.
Soweknowthatthiswassuccessfulandithas a bodywhichisgoingtobeallofourdata.
Butwestillranoursuccessfuldotthencodeevenknowwehad a fourorfourbeingreturned.
Youwouldthinkthatsenseof 404 isanerror, thatitwouldendupin a catchstatementlikethiswherewehaveanerrorandthenwewouldjustwant a log, sometextthatsaysair, forexample.
Youcanseewe'renotgettinganyairtext, andthat's becausethewayfetchworks, eventhoughwe'regetting a 404 response, whichis a failureof a response, Fetchalwayssucceeds, nomatterwhat, unlessthere's someformofnetworkerrorwheretheactualbrowserhas a hardtimeconnectingtotheInternet, theonlytimeyou'regonnaget a failureisifyouhave a failurewithfetchitselfandnotwiththe A P I you'recalling.
Soyouneedtodoisinsideofyourresponse.
Youwanttochecktomakesuretheresponsesokay, Soinsideofhere, wecandoiswecansayifrezdotOkay, thenweknowwehad a successfulresponse.
Andnow, ifwesaveit, youcanseewe'recorrectlygetting a userwiththatname.
Sowe'reactuallycreating a realuserwiththenamefromourbody.
AndthemainthingyouneedtorememberwhendoinganythingwithJasondatathatyou'repostingtotheserverisyouneedtomakesureyousettheheadertothecorrectcontenttypeofapplication, Jasonandyoualsoneedtostringif I thebodysoyoucan't justsend a Javascriptobject.
Youhavetoconvertitto a JasonString.
Andthat's somethingthattripsup a lotofpeoplewhentheirfirstmessywithfetch.