Solet's jumpinto a codeexampleontheleftsideofmyscreenwehavetwofunctions, oneforgettingusersandoneforgettingtheuser's post.
Andthey'rebothverysimilar.
Theybothcalledthespeech a P I fromtheJasonPlaceholder, a p I, andthey'regettingusersinthe 1st 1 andpostinthe 2nd 1 Butallthecontentsofthisfetchmethodofsamewehavethesamemethod.
Soweweregoingtodoisimplementthefacadepatternandessentiallycreate a facadebetweentheimplementationoffetchandtheactualAP I we'regoingtouseinsideofgetusers.
Soessentiallywe'regoingtocreate a functionwhichdoesallofthisinformationandallwehavetodoispassittheinformationthatchanges, suchasInourcase, thegirlisthethingthat's differentbetweenthisfunctionanddysfunctionandalsodownhere, allwe'redoingislookingthroughallofourusersgettingtheirpostandthenprintingouttheirnameandnumberofpostonthesidejustsowecanmakesurethatallthechangeswemakestillwork.
Soweshouldgetthesameoutputlateron.
Solet's createthatfunctionnow.
We'rejustgonnacallitgetfetch, andthisisgoingtotake a euroasyoucanseeherewehaveoureuroandwe'realsogoingtotakeparametersbecausethisisactuallypassingparameterstooureuro.
Solet's taketheeuroandtheParamus.
Andwhatwewanttodois a verysimilarthingtoeuphere.
Soit's justcoffee.
Allofthiscodeforfetchpastedintoourgetfetchandrecurrentplacethisentiresectionwithourgirlbecausewewanttofetchfor a particulareuro.
Thisisgoingtobeconvertedtoanarrayandinsideofthatarray, we'regonnahaveuser I d.
Andonejustlikethis.
Sowecanjustmapoverthat.
Sowe'regonnahave a parameterandforeachoneofourprograms, allwewanttodoisreturn a string, andthatstringisjustgoingtohaveattheverybeginning, it's goingtohaveourprogramofzero, whichinourcase, isuser I d.
Andintheend, yourcodeisgoingtobookmuchcleanerwiththesereallynicefunctionsthatyou'vecreated, asopposedtohavingtousethes, reallyuglyfunctionseverywhereingeneral, theideaofthefacadepatternistotakesomeformof a P.
I that's eitherdifficulttouseorugly, werenotniceandcreate a niceAP I outofit.
Inourcase, wecreatedthisnicegetfetchfunctionoutofthekindofuglyfetch a P I thatthebrowsergivesyou.
Thenwecanusethatnice a P I everywhere.
We'regonnausetheold A p I, anditjustworksrightoutofthebox.