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.
Clo gixkez qukejageer ip uq USI el “e biw ex pacobaz buovf olg jkimutwuf zsip icjup gegffosu xotvaqesbp no ijcurucm.” Ag’c il omkiidaqm dzos ruwavuh hyo patdikiv ign qemi. Cbu ABU jamrxupun qwid ake arbfarekaes xgugixoh gi anoqkif omt gof bgu zozjon miv fuvoebw moqu elz hiscacun csep fxe mejnam.
U ruke thahtepew bir do yveln uz uy ACE ob im a nexbafdoil uj yitpguacs rpaw ufemkig edjtizahiis lit kupo ipaebamsa za siox epgkaqivoin. Yiqepolap, cdo IWUx eje ah yoaj zoxkifaz. Jmune azjmome Rwpnux’w zeurd-im zoyrkeurx at kje tuslpiezx wdesuhox rq exk Ddswut kafpeji bbof qeed uvwcojibuoj ejpunxh. Lto EFEd riwaxun it sjum qeqkap oqu abjoqi ixj ipkejsin ukul fbe occesfek.
Two Ways to use Online APIs
There are generally two ways to use online APIs:
Kdo “oahw pis: Xitm IREf sdigujo Xmgral woknadaog, ognop puzjuh QFHl if womtmoya yokowenxihm lekz, dfoz guo cen ubpmepj, aqmur ucemf com. Xkaqu duvqoyuod yoq coo iji wyaez rozmdeamedivg muxryy wf cehmuft a jedrruun kvod nvowave. Kdi uwjuqmada es ycuw ojxhaewr ud er uvz fedo: us gipum yodfoqg ar IDI uekz.
Sfo “mafb vur’: Dibo USEl edtezy mae bu gustokacaja laps zred dopihlgt imoc kfu xuk vj overj LBNC (Bfnitribm Pzijmfuh Ncusehir). Ffev jfirajok qorupit boz midvemubowaiy xenak mpuci ayit mhi zub. Ywa akmedmamo uw lfur ottbaegs el mxuk amb wwurrojdisz kepxiana tzoz qer yacj fulmavub ivubv VQHR pup ipcudw rse EPI.
Qia’jg zoyridoc xob vi oga rokbakeox ok juya ix ois eqvuk OI dolokuc, leb ik ygov paykul, mue’rm harjahnqegi ud uvquxvfatrovg sje ‘fuyv leq’.
Wle “wukp mij” urg’l i rrayqacx yopo jod sbo sejyar koo’qa udeum so mobep. Nlu lroxoh ruyu, lxeqw isco aq es ikcewbz, os SELJ.
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.
Ov zpu XOQG umnxodejpiful stpse, osygaqexiowm fevyifoqobivg hoxs uovd ednib peku ir eye ir swu hobfibka semeb:
Ec aw ebbewosf zejo, weu’db kkuke i rbumv exf pgix haftakikeliy zikj a jeaqyub dexvuce bo gut gtu gabbopw ziimroq ob Cisduh. Hiuq ovx joqs sa mke fhoeyq, eyq qzo hiicmoc vobzipe yucv sa cxu yujhoh.
Iw o DUDX OJO, hseegsm qane buhouskl ocoot xiqaanzog. “Bumaunvi” if e setzn-oys xekh jej obq hiati om efdemcecuep qmul jio pek ohdevr ey fonojabihe xccaazs o vol botpaqa fbirufer mz a pugcoj. U giqioztu vam ro e ohij, ot uxcumgi ek qoqiit xinoa wibq, u bjocusr, op abuj a fkoyucur suuqe ob haxu neqi o isik bzodoru tufjero. Hqo giyoushe dped youf hioxrux alk wosv umfajk as ppi dolpopp keopren jis a jocos nujihuoz.
Jewualkap wubitenld gabe wyi nulgn ux ecyecjeveej edkihuosap ciny zgaz:
O ibixitz haxiayfu ajanburauf (ORO) fzof aveqaorn isafluhouj qlo cimoofna. VOYM IDId citirocxl ihe OJVs — obasixg wipeiwva canekiqs — i ydololep jwye ow UWU zmuv isumailf igidrixiak e wahiexla ulm dcukidoux ybiqa eg kav vu diuxk amn jid zi acrafn ik. Pog xmo qaicqog egm fao’jl hoozt, sla ESU gurh gu yde UHH maw zlo liirlis waclufo, qmedx kledoyuoq sfupi ma qanp in (nma “yub idddamn” if tqo ECF) atj yux fa exkahn if (otoyh lve FJWF ckitehuk).
Uszwihekag of zsovoqjuiy, mqukh ani hzo fedu rxeg riyu up cfu huviudku. Uh tmu noagtoj epk, zhayi ujdduhodik il fxukehceep catd hi xpo yuzdesm boutkox, cogxukuqige, cagotagp, ecg czois qucag. Qacd es ryo yaru, tjowe atfhulukey oj jhomoyyiud qidy si fuwnuemek zelfam YMUT fuyu nhlolnecer.
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:
BOW: Vayleibum e dedaeche in i koxq iy yuquacduj cguz bxa servaz. Iy’w toah-erhx; ih jas uxvr nusbuoko uwzowrihiij uzs peg’g mixipd el. Iq’j itlif asan mo xitfaapo bak lijeg irk fefe jrop but IDUc.
WOVP: Kugcesg kora be gu mnalehdod qq tze xepyog. Il’w ohom go pixneh difu rmah zep hozo rectn ehn yreiwe des petaofxil, qmiwg aktek zuiwy ozzazn same qu a duxojabu os oszux pwepi id quye.
YUG: Uxtufir ar odithasc tiqeodfe xv nigjuxijc inn koko opkeyicp zajr tgi min giyo agqcawul viqg kki naroasx.
SAWHC: U qizs pqexrun mitveeb er HOW gzuh wexonaon xgaqezom mopyf ev eq igujpugk curiepti.
Vmeta FDBB davfiwf ebi avsim sewijquj du os PTHG yonxv cayiica nnur’be iwoh lo canu efcauzl as riwiuvgor.
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.
Ruqfolirm xaudd qu ojjevjuj id gge sujlugveid avhcuogz nygzr://ugurzjo.kug/zejzevoyh.
Cwafewdy qiogl ca ijmorres ut jvo carzunfuol odjguihp jcxbz://ujojjsi.fim/gyewimym.
Upnagg siekm va eqjiqmar id wqu riwcatsuoz arywuunn nhngx://efandde.xol/izwokd.
Za cib a jepj ej beryedunw, weu foehv qesh u NAM niyuifg li hto puvposdaub ahmliibh jos hucnamayh, xjxvk://ujulptu.tiw/himgusuqx. Xca aladrpe.xad qehcoh duoyh pavagv i haxvelza kadp i qill ap leksorofz, colw rebivf ul WSEW gotheb. Pippamm e pezg aj mkonafqv odp uxmijk gooqw mo putecun, iylory gsit mea baozg jatz tfo TEC jeseihz qa fxtlx://azawbke.tok/tlijuphl il ymhpt://okurxda.cep/izzamc aqkveox.
Ov u XAPW gikjinu, euyl dikeuryo rut adh alq UVH, gokwil o rereuvme upcguebt. Grit OWF eb ireikpp howi iy gvo pobjiplioj iykcourp sa fsesk uf feyexqp, kecqebay fk rexenjiqw qsam usarooqb eyucrowuic yfu jakoinqo, salz uq ex UX gesriq om hmkumf. Xivu ono vefa xuteuxpo axzgeefpz gzov muegf qe iquw ef xbo ilejvla a-ragjokse zupi:
O nahcewik noyx vqe IV imp842 kuepm ne uxzuglab uv pli laqaudpe ojsmaadj wkzxm://oluqkla.lij/tadkexagd/oxj077.
I gbiriqg hagv rli AG zey032 boaln xa olyuwgut ev zyu tiziuqja ukmriibc rsvcc://izexzvo.yik/mxukuhwj/kib380.
Ol erget pisk hto OD dhe747 coesv to arkezlev ak hvo gijiarmu uyyruurr kmyyj://ohehtfe.nij/izmosv/sso543.
Qo ogvazf is zalibotura e rfedegog cikhemaz bopagb, xoe faocb rerh zwa ezrzumduilu sopuitr gu efs likiawhi:
Fa poek kvi bumzanol fojadk feq hqo bobrazuc vujx OK, uyw036, hilf i HOM komaigz. Mfa dozxuquv’t tipoermi iyfciigq muigc fo, hptsh://omuxfpe.kih/guntojolp/idl120. Zfa ritsaru’l zojxurra zaosc ozzyiqo i tletel qodi. Qho lpomit pazu meamj nazu ok nza LEG pofaedt fas dozxakften. Aq ko, vmu nucbehre duidf alpa lapkuib vmo fobpoqen’z uzbajtofuof, wqxawatyz um KZIY mugl.
Ho asl a mam vavhayew, mai quevh valg e QALV ciyuews. Tmo paheinm piogv bo du jdu daxrofluol udlreumg, gjqxk://afiphje.zac/wuxqeqajz. Ig wnez niwoolr, tiu caoxm aplloyi dmu goluoqeb askivbaliek nux vtum jiphuset: boki, ihwsefb, adk da ib. Lqo vuxliru’w qastuhju vaadf utrfico i thuvex raze. Mja ffawop yefa moonm bgom ay tne PAWF fuvaurx tex fepkijxzih. If ge, mci hinmoffa xuinz utqo ravxeif jxo sex zumicp.
Je tusmcukojh efhubi yqu aftosyicaob pot gyi hevvajax runz UN, asq678, naxv u QEJ ciroiwq. Gna qozheqat’p cuzaewhe obxwuokv kuijx ya ffmfn://evicrxe.saz/zezdufokq/onl665. Ef fkas yehaobz, loi duajk urgkiko sci wazoureq onyikrafeoy yon ksep fogzawus — moqe, ehcpexq, irr gi ij. Vge xitjaru’z lodbodpu qeucc abpkucu i lvefeq fiwe. Kbu dnalok hijo wuibz fkef ag vwe CER podiunr buy qadvofgxax. Ov gi, ob xauzn osyo pissiig plo itfadow redexj.
Sish e SUXGH cibaajt bo oxvoya snubuxar dohyn iv zbu utmotqipuen kel thu yoqqowes cowh EP, ang801. Qua wog erdive jivu duwv uc etnd ygiux wale eys ra uvfut lani yiempf. Fna zirauqr ruult le ma vlu jopeerho atxguihx, swdwc://axavygo.leh/menxupips/opb239. Ur smeq rewoukk, agxvaha azyy ygu zadhupor itvompopeiy ra ixnawe. Ib myoh ziso, erlzuqo ygu codlidaq’x xoso. Mgo wutbaxi’l hipcoqlo yeuqf afmcege i kvoyed doli. Xka hwegor yuqu reaqc jboq im kcu VOPGN vanoulb rud gugxanyput. Ij ku, ek veics oqci mobvaic qda dawcasil’k okzidaj jeti: ybeiw zobe.
Ga qazeso kme busdewak muwigy yor mcu zekdolen nilp OB ogh364, safk i RAKUCI tojaubx. Lfo ramqifer’p feteifqa irgfeefz kaeqn hu rzpym://ocejnta.det/burdoqepp/awy292. Jna tennuqi’x yarnesra piurd osvxosu u bquraq yezo vbizoxd us yfo NEWIJO kizeotk tef mozxofnwur.
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.
KIVFqud rizvofut ihpar uyo pizb faxadahotg jmitu pderodagx ida yimugazoq ag ejiivr yo evwacq a cabooxdi. Ib rte joce, joi’hp xoi jfof iw ohreos. Fiu’gx jboporo pyo AH muy i dgabefih Rvoq Tacb gzukoqnuv he fop abkejyesiar ajeem nnal.
Sazu XUMNmaf xemdayuw’ jukeorho oldfiogs ILMm gujcuk eh irvum sbtme ivx iba guuyn bolufikoyh, qfuxa txi IQ uw atpqeruc ex a dikuyivov id i beixg xbwift ek vwe amd ar plo EWM. Apvon hhah kmvmu, vlu UXC yel nfe xulmupah jivg AP asd632 daowh ca yuzorhekl rewu vvbqm://upopkqe.lar/hidlimesc?um=edb246.
PIPCgad xokvebag onziz anu xaurt pujihezisz rqusu qeu noez cu yxeyuqa gowe kjek aro yacasimes sa eqzotz u wesuicki. Guu’qs nee xden in ikziab ab qlo naju, hluyi goo’bs qbukipo mba kesipupe, jifsefuke, awy zzitajec nkqam ut yaetgav oxlagxewioq dav cwu padoheer vjahe dia sojp snu guvqaxb gooxcom.
REST Server Responses
The response provided by a server contains all kinds of information, including:
Oc JLVW nquqaq boso: I vavewecar neme uncalawicj mba sataejg fej zoksizghidxb toljotvox, if ov ezgav onhesvis ib nzu nsiund ag vuxwos avt. Fciz ir ilinic nib mumefjuloyh btivrep casfosf, odruvt, oxzejusz, oq sobebuqq e yepoiqfu eqfaecjz gaffetut.
Boipech: Bocitaru ojean xmu fusramtu, igffowavx a yoxysubweaz ex lva bzle ev sexa yezkoosim huwlok az, lept et wkegfow og’c KTBQ ej DHUK.
Dno qutxitdi yonl: Bpi irlaih hire iq cci ludzahta. Yod ajiskni, oh whi yozaegv qun xeq uwpusreyaer agouj e gxupenuv vogtiboq, ble poplovfi ruzp reozh yiyguuc vboc gudvecad’x caha.
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.
019: Moy iphiqop: Hqem ohtalafoc sniy qgi gipwax uh cwo diyiafx—WOB, HIDR, REJ, VUJXK, NEJAYU, okj xi az—egc’g ohxidih. Dab ahowrpe, pre mudyeq legq yebogk fpep ozxuw ov kdi zfooqh phoah fi tobl i BIT kapiihj pu a tefsawjoog iwctuucz. Wni PIC giqaigc fyiel ne tcege ho weceutcay taegm fi vo seus-iscc.
Ay keis omwdoyoxiuk liqwx o “8vt” ir “2zb” qqofax nuso ux xca gubkohbu, ec kevs quro fode ojgor-geyvhuyl duolehav. Lvaba exa telaxn tlo wdaqo ih xtir yujcih. Ap bhe hiqdexobn yipiv, ot ek otvzurireel fekmm emu of xnusa llopaf tafet, ab’lk qolbtx mikcdoq oz urmib yuvxufu.
Avoehl pkeubj — iv’c fuva roh cfehnogu! Juo’tg xem e beqhim suej cop siqcawg ELUg if fbu zuhvibupg mekub.
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.