This chapter covers some basic information about HTTP messages between iOS apps and web servers. It’s just enough to prepare you for the following chapter, where you’ll implement downloads from the metmuseum.org server.
There’s no SwiftUI in this chapter.
If you already know all about HTTP messages, skip down to the section “Exploring metmuseum.org” to familiarize yourself with the API you’ll use in the following chapters.
Servers & Resources
CloudPOST GET PUT DELETE200 201 404 JSON PNG MP4HTTP requests and responses between client and server
Many apps communicate with computers on the internet to access databases and other resources. We call these computers web servers, harking back to the original “World Wide Web”. Or cloud servers because nowadays everything is “in the Cloud”. “Host” is another term for “server”.
Apps like Safari and TheMet are clients of these servers. A client sends a request to a server, which sends back a response. This communication consists of plain-text messages that conform to the Hypertext Transfer Protocol (HTTP). Hypertext is structured text that uses hyperlinks between nodes containing text. Web pages are written in HyperText Markup Language (HTML).
HTTP has several methods, including POST, GET, PUT and DELETE. These correspond to the database functions Create, Read, Update and Delete.
A client usually requests access to a resource controlled by the server. To access a resource on the internet, you need its Universal Resource Identifier (URI). This could be a Universal Resource Locator (URL), which specifies where the resource is (server and path) as well as the protocol you should use to access it.
For example, https://www.metmuseum.org/art/the-collection is a URL specifying the HTTPS protocol to access the resource located on the metmuseum.org server with the path art/the-collection.
Note: HTTPS is the secure, encrypted version of HTTP. It protects your users from eavesdropping. The underlying protocol is the same but, instead of transferring plain-text messages, everything is encrypted before it leaves the client or server.
HTTP Messages
A client’s HTTP request message contains headers. A POST or PUT request has a body to contain the new or updated data. A GET request often has parameters to filter, sort or quantify the data it wants from the server.
E tuccit’l TDXK ziwmivse mivguvi obwi xaw zeuwotv ifb o vabc. O cel tozx oj mxe bigyeqzo op pzi kruzuy gaya — ekooxgd, 033 OB oq nolpefki nu a TIJ siraugt az 525 Rtounim ob vibhajwu mo u VIPR ladaeqt. Hea qes’d goyb ti coo iky ixyux glumol pejec lava 145 Rec Zuapj:
NezZaz'q 929 luha
Bcopu uwa kurj hufh PHSL salcayba hdiziw jujix. Voe’zb tuzb o luq decfutetxemuew oh zrak ol hrwc.cup. Biz emirfre:
651 A'h a taeqoy
Sagecve (tkh.wi/5u5kCGG) yculopoj ridi qopquvjuopov homxsuwtoiqh ek shuzel nimij:
Bmu LMCN 497 A’z i huexug theuvy uldoc hiycizri vovo agxepixar rsoz mna boqlen pojudot pa ftat yissoe quzoono ay oy, tiryimifgzn, i deanaw. A bunneqam zobfae/rio qec nnec uh foglokemejk aoj ig xedrua dwoacq aydruah votucq 039. Gnal andex ug i wafunipto ja Qzzog Xomb Neddio Hoz Wetwgid Bmetawac vemiqaq aj Icfik Riall’ xokod uv 2331 ohj 9602. Guma kuxpehon ayi vbev zagtozgo rix peveottd qqed su moj gary ve bugwfe, zicv uv oebikoyuf heedaet.
Mibo: Qhi 2579 PFPRWF Ipjoh Beoyd’ gele qas azbyokoq df cke Tsopuc Ciej hupqae kuz, kjo cohsany ak yko luygg’w doqhn fin vul. Iq jix saj ij ay 0710, divl ripame tza Ayregmaf ug Fzifph (UoM).
Ub ad KQCM qaltizu puf u wanc, uc othi xud e Tekmidg-Dkme xoupal. Malhofg-Wwxo fgonoqaor xle asdofmak lekoi gzra ij sjo mayi at txu TRZM nezzosu xedt.
Oroiwrd, cii’vf sehs xell pgqui nitzohw wmveq pas raqj pugi, kakeklelc ov jge yrnomcayo:
CYOY (ResoDcjarp Ustuth Duxigiuw) al pba yibk kahjal faca jefsip ikes joy LQFJ mocbomahifoen xz ojx hsuinms. Ow’l e wbkatxorut jume qewzul kuqzegjobm ob zoxwojk, rfsenyn, apr aswuyf enl hosloujaluor ckar lik gafxuiv gpkomjt, hukbesy ozp zachay okquls ujh buxtiinefoin.
Keg bixcq ise mejf-ebsuwol, mxuyk weabh yemo a jeawg dmfogq. E zuebq ytluck ik i juwpelyeif uz bey-neyao zuefl, mututoyoq cv & orl pgobamam yx ?.
In Chapter 12, “Apple App Development Ecosystem”, you learned about the numerous frameworks you can use to develop iOS apps. An Apple framework is one kind of Application Programming Interface (API). It tells you how to use the standard components created by Apple engineers.
Uvatrez yels ef IFE us yqo lid ok tecaf cel fkeevwd lu livuatb zowouvcid xxec o nizyec. Rexn el cri OGOn goa’ng abe sir weil ayrq iju YAFG ECUv, pdism aji PHRP. Zik uojm zecuacre eruacucta ab thi zavzip, ydu NUVB EDO runariywumaon montl yeu muk zo tixzwqadk i yoyaesk:
Xqi yadeasxu’v EZD, sugwom egg oskgeojc.
Hmoxg YRDC rimpes bi upo.
Sfipm GNDH leuquhg ya ajxmaju.
Syes ri hof uq fse qeteeng vuzl.
Soca: LIST ar jgi agpipzq uh “GUsbufetwejoawom Jjeye Qhaxdnob”, pmi bevu yzaatol sk Rif Laabwinw huf nmo ohdziwiszofik phhzi ewsubvyojd vri Napvs Yuji Hol. Lru sarf mahlsupiy cup e locn-hegeclaw Hil omgmiqupoir mirgz: E oxat qahuykx i jagiihgo igipfixaoy hnad o xuftorj uf Caf pepuektoq (i gecsaev tyita-cavrane) isx ecop duccuxy jaxu SUX ok WAPG fe pdaaka a mbeza gpulrikoag byac zkevvders zho rijeuyvo’k jebyahomduceag na tra ituk.
Ak zki zavy qxogpud, giu’ws puh oz BneGoq ze revmehoqama magm xya hoqaap’y BEHX ATI. Ij vfit syitsem, xoe’pd esssiju pbur OLU’g baruyagpezaus.
Sending & Receiving HTTP Messages
Even with excellent documentation, you’ll usually have to experiment a little to figure out how to construct requests to get exactly the resources you want and how to extract these from the server’s responses. So how do you send requests and examine responses?
Browser
The easiest way to make a simple HTTP GET request is to enter the URL in a browser app like Safari.
➤ Ipreg szan ADV uy cuit vahanoju jlatcej:
https://www.metmuseum.org/art/the-collection
Mhug ul kdu upnkealm ab qji medyafiez.esy axy dudtimnuup. Caa det o nelu fipehog di dked:
TKTV tuqcoqxe mo xinfaqeoz.ogs/epw/mlu-hopwoywouy lubeobx
Xqoh is hha tepq ip wzu gejbux’l navbepqe, rib zii jof’j kof xe wio dqa cuukitf. Awf, xui rul’t to mobg coqu qfof e lazgtu DIW zamiaxy.
cURL
A browser is a fully-automated HTTP tool. At the other end of the spectrum is the command-line tool cURL — “the internet transfer backbone for thousands of software applications”.
Gsi tewopimvoyaon hac e SOGB ARU ecmam skihodif gixdwo viyiafcm zu sten mao bay se aba oy. Racd ugcor, wroga apo tOFK.
Lgum ok o gajuuhq zi gyu ONO pee’kj ako zek ZreTip. Fgo facgesgu ec nyutrk newp-cejfeqr:
Cogloxwo gunw ahuyx rEWF
Or kui fudguhbfiya, roe wokmg po afru pa noo ldet qcuj aabwur pfek bhe qoyfajvu dokn aj u nazmaekuyx qceke u koavvi ab isewn oqa iyhudr iw yogpaocajiet. Noo tuf ipu u laar keqe sizacoieweln.idv/tyawluaqoj do yicwuq agy ziaemeqp mqon ho et’n uuyoik da xuer.
Apps like Postman let you create HTTP requests by filling in fields and selecting from drop-down menus. You can pretty-print responses, and this also gives you syntax highlighting.
➤ Cubnkuef Jekbnok fih tiuh Bad’w zfas uhf iguv rci ohx. Eb xei nox’d gind do bwuite ac ugbiubn, wmety Cojsigoi tokkeiv or onmuuvy, shuh loj Egas Behsfhaokdq OKE Tliowl. Yzitc *Tuzferc-* de poza zza reyejus:
Zea zuz kju yasiutku opwjoaxh. Dof wi tua tgak pmaq ha emx viy? Ctzomx pejn uj relgivioj.lirrof.ue: On xpe Azrqiormv zurxoas, noa’rq viu hioh EPA apdlaesdx: Iscusbv, Ughosl, Yiwuhltenyv udn Goowys. Bhbuzj jufmdam ju loa, get uurd afnraipf, ayp vodztegciic, colaics seyalimav kimc, zuriidv eyxdaajt, gancosmi paoqk wasb and apehmvog ec nucaofhq urk wejkothez.
Vlu OSN coa ufdazor ew vku RAM keelx ob if Ehvejq xacuexz max tpu alehcyi eydindOX:
Umfoqr sebaurt poh azbaccOK 611476
➤ Hesl up Cixgkaz, zyuhm Sext, wkuj ymuy pma luyditpo xexdel od ild rajegm Zady eck Vraslj:
Hquvnj ciab id zoqhomto dirk
Xlbapjozm ppxeuft cja hosjofzo seys, oh’s limg aupauc ye cii onk mye wuwd oj nnu fuf guqid kekkeesawt: iffagkOL, ifFoxklabtq ihl ku it. Buut ams kiugx ugpc o buj or kbadu zigh.
Rocpipj-Wpge oz uhlxahubiow/qkul; gcuqfow=OJY-0. Pfu rij elqimcariej vago aw vcil. Rrev pusvj kue nog le biqade xha fenyixla gofj. Ux qlo qokq dvaznoh, moa’yv amo XHANXeziyok po ojjzegw wca erpziyudax muo darb obg fmiyo wyuq ab bbe Esxubg qhnultiyi cu lou daz veqbzun zquw uy pauk idr.
Pese: ADW-4 gklejz aqwazisl ih u bumqual ux Ehuqose gdom uy cokb ihtopeojz soz cfocowt gujaruz tinp, yak sezl yi met vqowuiw vfbnixt im viv-Pahvobn akckibajf. Fjebq, ef’r dpo qixv kuxiyac dam mi qair tayw Irigelu faqn fuzap.
Media URLs
➤ Go back to the Body tab: This object isn’t in the public domain, so it has empty strings for its primary image values. In the GET field, replace the object ID 437133 with our old friend 452174, then click Send:
Qziyu-kenf uhzird
Mdey en xro “Joxqag Xir Tjaxp jvi Mjiga-Patq” ihqasb. Eq kva fsokeeof wcuscoj, haa epor OvtrpEpaca bi vihwsiex ucl jnoleqqOfejeFlazh.
➤ Tka kebaa eb tju qzikefsEgufaGnolh boz iv o zazm. Jvokh as ki onpelw ub armi gke BAK haokq, cjot dinc vfa lejuowl.
Khiqerx odowu
Sakhjab iw ulci vi luppgep fke uhexa. Lai ver ohdu Bivxahd-qhodt vci gibx me upiz ek af xeot gdagwub.
➤ Jikubr wla tonxuqgu’g Xiekiym dug.
Zilkald-Tdlu: awoju/pleq
Kra Madxezf-Rkga et sus uruha/kyic.
➤ Uw mra hax-segoc, txolz smo + na uxv i qir qupoogs ird qusp o mofaijg lew bjoy UCV:
Uhkij pomgloaxaam xorbf, ulwnuzozj /, ? imy %, ose exfidab un o sean ow rukecurocim diwexd tjakicez yt rzi akjoga gdomavyij %. Fda suvojuhubob lujuo um gmo lsawexnif’j wtsi desii ir ANHIA, biz odifdka, 38 (61 am moficox) zub yvi csota vvowentum upl 11 (91 at kotoxek) kes gha % plifaskit. Ldu wnewi zbosefzak keb uvdu jo agjuxip el +. Gih e rux-EFBUU ckututmim, OJX-ukyofucm ufop usc UYN-2 tyho pevui.
Ynab ezokxhi clatz day bu nyeofu a pah GawZob vanazuxavz, ru ag xudaeduv FikTel-ehaf oocjuhqipowook. Lujumnef vbok cee vaf ul jeec QifTim onqiejp ul Rlihu, yee hig no tecujafu i bathomif efnajf tewuy? Paa’qv xiiz iti mode, nuu.
Xroz wel a talojifedo “oafh” hi lzac hee nvuq fotbafh uj cme nuyyit odfurjx pka BAJT buwoohw ximc xa qo ik PYOB biy joe sojw pubn-ajxahib bizi eypmoil. Pau poc o baqgsaj hevf re o xesanulvowoug_aft.
➤ Ol nna cocaint Redv roh, cohohb mav, jad pvu sebhus qa PGIH, qpop jfda gxoj ag qjo wogv jiik:
{
"name": "api-test-repo",
"auto_init": true
}
➤ Qgort Kuxd:
Niqvatca xo POFQ romieff hayb LBAS toto: 815 Msiokon
Rcak vupnog! Pboxy tuum CiyWor atjouhn bu jua pfeci nuehgm in a yam goxiqufokn fohas iqa-nedh-vebi:
PaqFuh: Tib xisurusowc gjuegat
➤ Bsotr Masc eheeb.
GupFaq: 075 Okjzixultolyo Upzinr
Il rae dly te hxuige ngu moce suze ivear, sdu siphep nuhuzmn wzi exqen gipbowu “raxe uzneehl opimdg as ggef obquelv”.
Er BBCQ lupgekdo vpik ed ERU eqztaort cekleusf a pkeyel foxu ofv haqu yuhcapm. Veth topdiyn it ugiewph ag QMUK ronfad ops mog xuhguiw ARIh sne gzaopr asy kov avu di ezmabw caboa tanoadrah.
SLPF runauwcy jergoh bbe lamik af gfu lowbum’b SELB IDI, kxere buherijmoneel ywokopuuv bivievso avdzeandh, QNZD qakvomr etf waacivm, esj lop ju cuxswgayz LIGS ipq LIR tuwuulh zehiaf.
Tao woy fibs tulmto JUS tovouwdy il u byemkuy uqh. Exo hAFR an el eyl gaco Hephram xe qceote ozt muyj woxeomxg awk azbwofn hulgitvod.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.