Andnowtogetstartedonthisvideo, youcanseethatasalways, wehavevisualstudiocodeopentoe, a blankprojectontheleftandontheright.
I actuallyhavethegraphic.
You'llplaygroundforthe A P R thatwe'regonnabeusing.
It's atcountriesdotTrevorbladesdotcom.
I'llleave a linkinthedescriptionblowforyou, butessentiallywhatthiscraftkill a P I doesisifweopenupthedocks, youcanseethatweaccessthecontinentsandwecanaccesscountriesaswellaslanguages.
Andwhatourapplicationisgoingtodoisit's goingtoquerythecontinent's list, andit's goingtogiveus a selectboxwitheverysingleoneofthecontinent's fromthislist.
Andthenwhenever a userselects a continentinthatselectbox, it's goingtogetallofthecountriesforthatspecificcontinent.
Andjusttogiveyou a littlebitofanexampleofhowthisworks, wecouldjustdo a queryhere.
Andifyou'renotveryfamiliarwithgraphicyou'llorhowgraphicyou'llworksonthebackend, I haveanentirevideocoveringgraphicalindepthinnojazz, which I'm gonnalinkinthecardsandthedescriptiondownbelowforyoutocheckout.
NowthatweunderstandhowthisAP I works, let's comeovertovisualstudiocode, createourbasicindexdothtml.
Soit's include a scriptwhichwejustwannahaveherewith a sourceofscript J s.
ThisisgonnabetheJavascriptfilewemake, andwe'rejustgonnadeferthissoitloadsafterHTMLsectionloads, andwecancreatethatscriptout J s manor.
Now, beforewejumpintopopulatingthatselectboxthatwehaveoverhere, wejustwanttotestactuallyquerytheGraff, kill a p I, andinordertodothat, we'regoingtobeusingfetch, whichisbuiltintothebrowser, anditallowsustomake a P I requestandcalls, andwejustwanttopassitthiseurocountriesdotTrevorbladesdotcomThere's goingtobetheEarlportionofourfetch, soit's justputthatintherelikethis.
Andthenthenextthingweneedtopassourfetchisgoingtobe a bunchofoptions, whichisgoingtobehowwe'regoingtocustomizeit.
Sofirstwewanttosavehimmethod, whichisgoingtobepostThisisgonnabe a postrequestbecausewe'retryingtoposttothisgraphcool a p I.
Andthat's essentiallytellingusthatwhatwe'regettingbackfromthe a p I isgoingtobeJasoninformationandthenlastly, here, weneedtoputthebodyofourapplication, andthisisgoingtobeJason, butweneedtomakesureweconvertitto a stringtobeusedwithfetch.
So I'llsayJasongotstring.
If I andinsideherewe'regonnapassanobjectandtheobjectisonlygonnahaveoneproperty, whichisquery.
Butbeforewedothat, I wanttocleanourcoatupoverherejust a littlebitbecauseweknowwe'regonnabecallingthisfetchquerymultipletimes, andtheonlythingthat's gonnabedifferentisourquerysection.
Sowedon't wannahavetocopyandpasteallthiscode.
That's what's justcreativefunctiontodoit.
We'rejustgonnacallitClearyfetch, andit's goingtotakein a queryofwhateverwe'regoingtobepassing.
Wheneverweselect a continent, thisfunctionisgoingtobecalledandit's goingtotakeaneventargumentforwhatisactuallybeingcalled, andwecangetthevaluethatisselectedbyjustcallinghere e dottargetdotvalue.
SoifweselectAfricaasweknow, thisisgoingtobe a f asthecodeinsidethisvaluenow, withthatoutoftheway, what's createanothervariablewhichisgoingtobefarcountriesandwe'reactuallygoingtocreate a newfunctiontogetthesecountries.
Andinsideithere, wecouldjustdo a simpleconceptthatlogofourdata, andthatwasjustcalledusoverhere.
Andwe'regonnapassinourcontinentcodejustlikethat.
Andsincethisisgoingtobe a asynchronousfunctionbecausewehavethatthengoingon, whatwe'regonnadoiswe'regonnamakethisanasynchronousfunction, andwe'rejustgonnawaittheresultsofthis.
Andassoonasweclickononeofthese, forexampleAfrica, We'regoingtobegetting a listherewithourcontinentandinsideofthatconfidentwehaveallofourdifferentcountries.