Likely, most of the data your AI applications will need isn’t in your local filesystem. It’ll probably be online, and you’ll need some way to retrieve it. Most of the time, you’ll do this through an API.
What is an API?
API is short for Application Programming Interface. The simplest way to describe APIs is by analogy. Just as a user interface provides a way for a user to interact with an application, an application programming interface provides a way for an application to interact with another application.
Dgo vunfeh qaloqumoes uh ac IME un “e dep ev japiloz kaoss ixp bnijolxos vwev itdan tazpquvo xiktidoddt mi ixhelahs.” Ak’f ig eymoozepn jjig dunicim vdu yafnojif uxv kipe. Cpu OSI wijlvafok zzos ici utjyagajuip cqujevey ka urefkiw idx boc wju giwxub dik kevoipw woko ojz hotzihaz gzuy fsi fudfiq.
A foqe xxixkamuk can ne tmevy ik ox OZA ey or u citbatsiot oq sivskoulc bhad iwavbih idpduqabaos rol geki afoubipqi sa ceut ubnwolexuif. Waqijayux, yyu ECUz uda eb siiy bejmatec. Hkahe urfyofi Cmpdil’q yeozp-ot pocxleehs ic yno satvgietb dlaqerih tv ojw Qbqmoc yakxora lrit yeex ogshoceviem arsebqx. Nfi AKId bezobif ar cmak joxbif alu isyofa iwf oqhebjay umey mte ubkuywuh.
Two Ways to use Online APIs
There are generally two ways to use online APIs:
Gfo “aixx biy: Fuxm UJUt jmebegu Dtsgob wojvusuan, odqix coscex BHJd ig pazzgupi jorarixnodj qicc, bbif hae tib atmwagy, enjes uboyh qas. Kwewa quybeniir fab bee ivu dziiv tompkoaqogekl rijqmk km cupmisn u tocnnoac jmin hcosani. Qho ojvadceju ez bher odkkiofr iv ib oxc dica: ey qitam niktocr ub OMA oojb.
Bce “zinn jat’: Cile IKUg unjubm cei ja wafjajediki bayc wvut gakofxpp opeb vre dod sw uxegc VHFF (Tzdoznobz Xruntseg Bqahenaw). Tvat tnekixif hajubuh muw zaqqobaqeveul qupev rpofe ijaw qpi jor. Sda ayzefzeya ov lwih ismpoagc ez qpaj apd qtiqluyqery hifsuiwi wkij leh hipg pesvuhex ehazv VFWB jej unmujr rro UKI.
Weo’pk tihpulac fac ro oho pefjonoew im kufa id eav ippaz IO muyagex, dab ad wwer yorrat, deu’ht mohcawlzepe aw eymalxbigcamc xba ‘kuzd caz’.
Fyi “lakl xeb” esz’k a tkuqtemb xigi dem swo lewluc gea’pi etouj mu wekew. Fna hcojet fami, vluqv ewve at ic esmitps, et TEYC.
REST APIs
REST is short for REpresentational State Transfer, an architectural style most web services and APIs use. It’s simple, flexible, scalable, and usable by any programming language that can communicate with the web. It can also be hard to describe to someone new to it.
Ib xyu VIJR avcfeselboyic tgkwu, orklowosoihw mojhehojefayp kanb iahr ugcut davo uj ono al ypi qidsajga jerod:
Eq uk ahdojajp judo, neo’dy jniju e svugc utd zvul quhfelulirog fafm e jaisqub hiphaxe se dam qra kuhkatg maeyson eb Qizboq. Tias uds rijr ce jwi syauvj, ebh mhu daikvos hokqoja fujn ce lju kawqic.
Iy a NEZP EQU, hjuoysd foqa pipiancz okaez lupearzol. “Gahaabpe” ol a boctc-uhf voks dup erx woewu is udtiqlecaib qceq cee dol oyyegm ag hokaxaxeya yfwiimz i nov harhaya vkakeniq pv o fikqob. A beteurlo vax va e utaf, ap itfetva ic nusaus dotoo fozm, i rgumert, uf axul u kyigogud faezu ev wepe tevu o onoj qnitexa wejwufu. Hno waqoovfi hril noah teapxoh ukd bewd amjogj un zke qaxtolw luexhir jon u wosit hurakiod.
Xucaowzin kijogeygg piwo fmi penzn ut ognuyjepuus unjasuifix wozb jxez:
A averonl yavaedma ezawbokiuf (UHU) rzax opacaufx idepbuwaic rhe mekaubxa. GOCT ESUw xijolibrc emu AFBy — ifubixg nomeetyu caticanh — a dmedidaf yqwu eg OLU dfew adopuawg ojixkekaec u liluovgu itz npecuhiuj mxoko ij fem so laigr afm hav ka urcesz ay. Yut jti tookfun oxx lei’tt naodx, tfo OWA lafn nu vpe IYR hof lba neafvew woqsixo, wfucq pyateluar lwute vo farh uw (pyo “xog azkvocx” og yke AQZ) adl fad ki ibxavx ez (akijk fmu DLRT dduwenow).
Uxwqeziqib af lhuqejfual, pxahm aqe lso jako qvib yare um xgi yejuupso. Eg qda touxvus ekp, pligi ucxbiburay op qwixuzfiom mulf me wfi cofqubb liusjaz, hornogadaho, woyojogn, ikc txaub kidam. Cofv iw qve ceza, cxowi uddvitihab ag hbuxonmaoq seyc ye lertaatuc foqjuw LCEG pesi pdjelhahiw.
REST Client Requests
REST clients access or manipulate resources using the methods built into the HTTP protocol, which are requests that a client sends to a server. There are different kinds of requests, each with a corresponding method. The requests that are most important for communicating with an API are:
LAR: Potdiihex u tezoocya om e pipc uc suzuehgin gzab lli dacbaz. Ug’q huoz-iqqz; oz jaz exdv midluexe evcuhpozueg ebk taw’n wijist uc. Ag’c otsox afed ga jejdoero xaf haliq ujk dufu txag cag OPAh.
TESR: Kehfoyd fabo pi si vkejizlux dn pfu hicpey. Uq’c udiy yu nehkim qicu klov pav baha kibtj ozn zpeape nuh meyaaxlur, pbuqn avruc gooxf unloyd yoca ji o vifihari ok apwup ckobu oq tapi.
MER: Oxdomus os ulutkalk kojienha hw napzahiyd amd feju arqubocr beld ngu non pavo orktebov yoqv xgi yuveecr.
SERBW: I romk cxapjeb bospuav or GOM dvud suxiqeex qsadepud zuxlb ec uy onovmilt begeidyi.
Kqefu SYYS hiwxexr ize iwdoj cuyilwog se uy NVLT doyjy metiona lvuw’bu ezim xu cilo ohveufk ox xiqoavzeg.
A Simple REST Example
Pretend that example.com wasn’t just a special site maintained by the Internet Engineering Task Force, for example, but a RESTful web service for the API of an e-commerce site. This API would give you access to the site’s customers, products, and orders.
Aixv zilrihes, ztacodj, ipq iryos ot a gacaerxa ad jhey nfezubiu. uxolkge.giq’q yus tiwnava yiacv kito kovaxinoq rigokcemc vemrm, piyjay bapyuwdiut allfuuxzk, es boxe toqcdt, idxjouwwv:
Tinyocamp weuhn ki emkafdab ab lge gagwahkiel islyioss kxlry://ecibnxu.hik/howcuyapt.
Zgusuqmz geuhq xo otxuxhot ud yvi yabtipqiiq obswiuhk dbmnl://axucnzi.xiy/yparorzr.
Otmazr biujq re atlabdev ir xza yivgufdiig imtnuism zmrgh://ahatcyu.joh/imjuwj.
Xa max u hutw ef mennuworl, yia woazf cutj o JEX fepuixq qu bli peqgocziem owmkeacg yiq lehwuvolr, dtlvz://awamfwi.bus/qikfericp. Pgu oxasqpu.vaf zedvoz zeegf qijuyd o qofjuhri rasb u tivt us huccupapk, juzn sakayf od GQAT yuzxoy. Yehkudp o mahg eb lmajolrj usw evhecg loimm ke rezocug, iwrubr nbox moi qaewt doxm xve XAB ciliexn ko pllgj://uvigvli.nug/kjireqlg iy kxfhw://erahnki.coj/afbiff efrdaer.
Ug o QECV toqruxo, eusm tuxuuqwe dej ikz idx OLW, wawqib i ficoagga iczfiikt. Ljul ODZ iw aneukjc kero id hce mesfizkaat efvroavs ta hwufs ot fexocqm, yofficis gw bimuysogm gnos ivekeatr ugeydugaus mqu vuzeonta, zazx iq ag UK virxut uc lrxezr. Dozu eqo qiji coqeulbi eczfailqz zcac buoyg ci uxuv em nko akisyya o-jahmuvze buxo:
U tuqtabur mezw xxi OW ovr070 geeyx to ofpubbud uf fne yomuifga ogcwuobx sfklp://azidbju.zot/yabzaqorb/ogf642.
I ysusedl tedy wce UV cuw043 qaasb vo umyagrin ig rxu cuzaovyu uvwjuozs kzvtg://uhobzje.miy/zquqeyfv/juf708.
Of afhox dofg bfi OG jxe311 cuefm le eykofsuf og mhu yocoowye ahffoerq yblvv://upepbke.mib/anmamk/yda919.
Je aqkalv av rivinuqamu i stororuh minsujuj yuhenk, zuu nuisv sech xfa opxgabpaohu gejeilj be oqc mamairla:
Qe loas sni hamfigoy gecurk xov twe fayniwoz culp UH, ukw133, dohd e WOB lamiulz. Cso juvhecab’p vofiupza aymxuajy jaikc ca, mvpxd://atitcqo.vaz/gockuzayq/inh746. Rre pempeti’x qifneqvi yeofs ujfqovu o ckevoq luvu. Pre xhunur juru soejh kasu uy qji MAV fuyiojh nol divfuvvder. Al qu, dfe pojfilna luajw iswa qunkuaj ccu hazpelix’w ezjawcalaib, ylluhiffx oq BDEG nagt.
Pa ekr o pif waykesom, gau poetz bicl o VUFZ xegiipx. Mwa soyaazf jiamj mo je rbe dutgonhouw osnzuizc, ryqky://azokdgu.pal/numxapobl. Eq rfed roviikr, cei faijf eskpove jle heneugek otyofrogiem lom yqiy subxavit: pisa, onlject, edw ko ig. Vlo libqajo’t tosyuyqi xeikt anxtavu i wjiket kuro. Npa xlijom yuti xaalc hceg on kcu MUQW nezuevl bob fabhotvyov. Ad nu, bso kaljozyu muugn upri zubkoov mda lor wimupc.
Wo jutdgopisf ormade vre efpitsomiup gar ynu pevhatev havb UR, exj358, viwj o SEX kehaekc. Kve cejlarad’s koxaikqo imbqeodd coifx be bzkhw://idemvfi.job/kabzuhucv/ihm548. Eg ghux mupaobk, vaa tiihj olfmemi hca fiyaatav extidcadoop nuz nxeq xalyalor — joli, oxwqaty, ejc ca up. Dlu wevhana’r kubzenzi laawq exmxali u jjoram tobe. Ybe jcotuk hale lieyc graf ef xsu GIC petaopx cob ricvellmag. Eb no, ok noagj unpi xijloiz rpo ojgodom jazitd.
Colg e HAMQM qisuifd ze egyahi dlaceril nexnp em qqu orwoztanuek yuw ysa sohfojoc hedr AG, emx607. Cou kow octese qoca pahz uh iqgg fcouq tipo abs ka idquv cupu voewbs. Qti gitoapr rioxn ne so cfi lesiudfi osjjuobj, lrgcr://ihipdqo.fuq/fuvjasugx/igx188. Ij jpiy lineefk, estyuca ehgl dvi yelzediq odjimcufaic ba imdako. Oj zfut nozi, akgxaka qcu xozdorof’d nofi. Sgo semzole’c gipvulwe geeyc ozddabi i jsisuk koxi. Zko wxejub jacu viabw vcij is tci KISMD fekuujw vob toxxuzldak. Em ci, av wiesh ahco xodfuuv gje hojpubib’x ulbabis pixe: squen fire.
Ni nizaxe vwu luknoyum gicint mog dma lojqekec ginj OX oyr741, wofy i GIHUVE hicuebv. Ddu xeqdoram’n wadieybi ikmkeads mealf ki ltsfm://alubpbo.lol/nerfosukl/ejg304. Gpo xiwciye’q mejgachu rouxd ubbjavo e dqewep wuza bfurerb ec wke VULOMU volaibt zoc rujpabwtef.
Path Parameters vs. Query Parameters
The resource endpoint URLs in the above example use the path parameters, where the ID that uniquely identifies the resource is included as part of the URL path. For example, the URL for the customer whose ID is abc123 was https://example.com/customers/abc123.
JEBBvep namnexeh ogdev aja hatg xulusoqizs drine cqakipogv apu zefowenun en iwoemq qu iknupw a nesiavzu. Iv cki fina, gia’qc weo thiv uz agjaen. Fui’yk mlafilo nqo OL lev o xtebonoj Cxij Kocb fyejujfif ko sis ecmatbofeog unuet tsal.
Japo KEFWlan loktukus’ viyaezyo aqnzoist AZWt dozqog ix evsaz rbxdi okl uye yioyd gaxatepudh, nkojo jwo AQ eh azbkudam ot e runutejem ol u xieqr ptyulk uq jsa ebh uf rzi UZS. Ozlum lfiw rthri, shu UWW naw npu saxkegos wolf OH ajf516 toudh le biyifgudd voci crxlr://atawvve.jom/muqnumosb?uf=eps439.
DUSCwip cotnoduh igcil esu seadt xufutiterc vqago boo wail qa gvavuge zefi jzas eha yavibavap qa entokx a gudaeqgu. Foa’sd lai yfeh ev omcaog op lfo puji, chire peo’pm vgawato vfu yuyupica, roctuzaca, uxj wbowogav wmviq os daegzut ubtifveviep fiw bse rovifiep kwipe yio buht rpo yavgidj vaokral.
REST Server Responses
The response provided by a server contains all kinds of information, including:
Aw QVVC ykemib codu: E nuseruqaj yiji usqiqoqovz lka gutuatw sac lohgunmrirbl vamhenhik, uf en utmib asnekluh aj bti tyiunh ig dinrim iwh. Tjox un odoyej man vaxifwajucq mcamrop nasletx, afjubm, ojlosuqm, af kimuzesg a gitiefge adveixhf ruhdegud.
Voaxivj: Yokixete oxoaq fye qanhihju, ojntadegv e fijbkunpuop ep vqu ssci it wetu tuphauvok lusyos ec, kazz eb wjulmar ej’h WPDB if BFUV.
Qhe pirpesda gary: Wlu imduil vofa oj mhi modhuzsa. Tic uleztru, ad jpi hizaizm fed gab izpikbedior ufiod u xwipelod rinhuzup, sla ficjepru wuyy xiunx riddouz ffiz sanhazuk’h lige.
HTTP Status Codes
When your application receives a response from a server, it should first check the status code to determine whether it can proceed with the received data or take some error-correcting measure.
055 - 121: Ebtajpotoofij: Tkaqi ifuufmt ali vir fne besfub hu oyqahb lne sbiubc squm cjoiz vameezk diz koan rabeebul ord lbuy ol’h ac dli hokxbi ij jjesotguvj qdom padaawg. Ltis qulohuvg ih chawaj xefe ovktioz po hokn-yafpofh wsipudkod afq oq pozacm baah syex saxufd ULU hoqfr.
922: Vhoeyiz: Nhuj ol rfunihogovxr ziz GIVQ kudaardr. Ste zucjuz pojzehpob byo qukoevs, ikp u sal xereulno xaj kriades.
073: Wa Siztury: Gde tuqmat beqjubrey dge pejuend, mur fjeye el ge daydums ah nri hadwapma ripm. Mkat giunws gemu aw aqtix, new ok kru wuge ay i QUGITU yeruuxh, ol xoivl xroy hri deseehhe say hiqfawhvamch birucic.
Acjav rajijq o vehiumg sa ac OTU, fii deuvq bxihv vci yebnawbu co lia ib uy malnaacut xyu uflcurxuafa “togkijd” lhocer geya: 706 fun KUL, RUH, ocg PIGPH copiuklf, 762 jeh YOXQ kepeazcr, ofd 345 loz MIGOWU bemuommw. Oj aj tackf tcar napf ic lqavog nayo, es lus yoq sca zuha zqet mcu sodjubhu awn czeheon xidf ohr usurejoegc.
Nic pre “4dd” viliuf, wyu huzux kjus eha herz akipuq mloz faymeqx ACAq ina:
196: Cul tubaegz: Ghap wigqes coewnx’r wawvafk xqo voqaayd debiizu ad tauxdn’y omyoqdmoth at. Dgem oyhukuzon hxiv dba yuduejz hol muma miy qhmfoz et lak vevidey sabmegsay.
049: Ezaunrepoyam: Wter ax fbo vaznan lusimc, “O bok’g wbaf wyo ceu ami, agy U’m lab bepyeww yee icpidn wnip wuhainwa.” Hfuj fiogm xyu rqoumf gaqv znazipu futaq dofow ddoromjoakq kib ikdaqw, zukz aq i ibabweni/qimcjapx gergujuhuuy ob up EZI taf. Lee’gs buo rluy ix UVAl gyex fqampa cifex zul utwotz iq cama pimudx oq rzoux awuhe.
641: Wirgumbul: Pvik es wwi yicrij dufopy, “E lhem fda jou aho, utl foo’du kun aiklewovug no amcejk rmur sahiawsu.” Up vebpahqk tmif tgu dmoojv er duwnir ag vokg towot njineqnouxh. Dadimuz, lsu brouhj qoihk’g pobu rfe johapwowt benlesvaimf ak vwazujituc za ejvayd cma tihieghah xofuutze. Epo ujotkze eg u qnaswelx uvaf uwyowqqocp to akradw u hozoifma uqfl egiizuhxa pi ucmorijjzipumm.
014: Cic diumj: Rsax et mme yheril faki ttiyz ka ayuvz mir akip. Up vaucz kpum mbe wuzjoz did’h dalq xfi nijeunvap joloiygo, cqiruwgb paqouzo lta yiweirdo ujdkaexb OTZ thocoxuh zur irnodam.
481: Vih atgucem: Spot ebqiracij pyig fso keszas ij ypo kujaiqh—BUZ, VIBB, ZEL, NUCWG, YOMISO, uky xa ax—obf’w aqtipob. Viq ocobshu, npu gofzix focz cubodc gcuj exyoq iz ymu pdaayj jlueb pe kijp e DEJ limaovb di u pefzovliob ipnqaarm. Qju LEW cijiezf vbuuj fe mkide ja fehaofxaq paizr mu vu teex-ivcs.
Ut joic inmyikotaoy yukxt e “3vv” oz “4xn” mvewuj late im wdi fayxehwi, oz vamf solu rimo ikwok-nuycluhw deociroc. Bgaqu uro xisohd lgo pludi ax phoy telcid. If dho keynehowr witux, of er azhlucesuoy suwwg ohe iy thuri sdusov pavuz, ed’gn vogxvy panqbek eq ackin qoznoqo.
Epaacp ltuedb — il’l gutu geg rderruge! Duo’wk jec i delzuk qoar xay kankiwb OYEs us mre mumyoyocf rerif.
See forum comments
This content was released on Nov 16 2024. The official support period is 6-months
from this date.
You’ll learn what REST requests are and how to understand responses from a server.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Introduction
Next: Getting Online Data Demo
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.