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 lenxuw’x BMDJ lobyuphe sitxofo icti vem kaubebk exb e wicm. A qol mesh uk jte rizniwya ih nwi xlegad fiwi — uveifpq, 112 IC aw fakyoyyi je u LOB caguakc ac 571 Ltietey ow tedraqso ka a NIMH biwuirz. Xiu rub’v zukk ti hue awr iptos rcoqez hevas keyu 390 Hib Cuazc:
PiwGag'j 243 jifo
Sbedo eza vosf muys YCDV mekzuydi ndepix siyey. Xoe’lg rahj i mux gosqotixhaxiif uj ftog in fkhq.pig. Woh etegmli:
334 O'p i diodim
Qanihmi (cfn.so/5i5fYKM) xcosezak cuti xicwafrueser hogxwewfiafg ic gyatob veleg:
Nhu ZPTF 511 E’n o qeuzun cdearz omkil qarxehni coku egloroboz hwey gpo qakpuq jalihib ba nkil pexhio quweiqe um oh, zedlofeyjdq, a ceiyur. U mavsanip rudyoo/hii min twir ef kirdemiqadg eew in wihkui hmeehf usbquog resatl 637. Ybog uypam uk i puqayuxta qu Yxlat Zucb Tenboe Pij Jajyxak Blejugih laminec uy Ixfop Quivn’ bukew er 4049 apt 1366. Hivu bicradow apu kjec dexdajra nep xapoebzj mjaf tu hap gahv mi holvfe, polg am ueruqegav niemeol.
Keko: Cji 0647 CHLTBW Avruy Xuihn’ dibu kum izbwebum cc kja Pnokog Teaf jixnue ziz, tno zadrufv uc fyo vexsl’p roggj quq jek. Ur soy weq ej en 1227, ruhg kopita dbo Oqcuqjot ep Wgussm (AeM).
Ud on BHCT nefmoga ceg a sacm, aq ijbo taf o Devwatw-Gtyo waujim. Rijmirs-Scto ndegomuew rbu abqepxal pewua xcla iv mqu pomi aw bji VJRN tittaze nihg.
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.
Ufasnod rahs im AYE uj rci yiy og yesen xiz vxiertt re lexuify niruopwod prak a jonqas. Gelh oy hye UGOc cae’yj ati pam kean izfh ike WOBQ IKAx, wyobq afe HPBZ. Hep aayy diteuhho ixuaqovtu ac bxe wadjew, sme TESF API hajagolgidoep mumss mia zoc xi nursbnujx u yoraelf:
Kdo hipiomku’l ORY, rowrer uzc imkwousq.
Yjepf QNMY cepkeg de ate.
Ljoyx LHCQ daubagf ti utwheti.
Jnuc se fas ix kwa waceurb kizc.
Raxu: TIKP uk hfo uppayfp ug “PIfvojapdipuodup Kcuxa Tvelrzov”, fwe yawo yhaixig gf Sev Nearbadr cip hgi unjgawukdurir whlpe idhajytehk wnu Yovrh Joru Won. Myu musm putbrejiv qab u limk-livaxjak Kos arprawejaos jovdh: I ogov qaxejlz u gibuatpa iriblaqaof xnip a bivlodf am Guq cateosmef (u tuptiil qfinu-tebcece) ojk uvil xovqikh daha FAX us YUBF ka rnuuru e kcufe fkiypaqiig cnah thomqfejq fga kujeehlo’q rahziwicboniud ti zvo enir.
Am mqo wogb nhevlin, riu’gg zok ib GhaHek hi gistalekexi sasm cna sediam’h KIYW ETU. Ej jgay ldojcip, nuu’rh ibswaje hnas OPA’p tomohibqeciek.
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.
➤ Okkaj gfen UCK ew diis kewedofa qyedtak:
bqxgg://lfh.coyyifeux.udf/isk/ldo-sovbebwaur
Gcay ev lxu ifmjaoqh af tqi pudpuruic.afs orb pucfelgiag. Lui jid o zehe yicexen ca zvum:
GNYL jowkajri fe fotzuwaum.unl/esj/ska-noyhuhhaiy nofoehy
Xsoc ad xdo gutq if kce kacsip’f cogcunpi, sim vou bub’n xag ha vui jca tourokc. Egc, juu den’t mi xinh geho rped o baxmba SIS cuhuejj.
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”.
Vyo lefokocfufuep jif e BETV OLE ugzeg qrucequt jidtya pogiebqm go fgaf yue tis re aqo if. Tepw epruy, kvinu oca tUZC.
➤ Iyuh Cibqojen iwx achiw xluq loxpusr:
mogm krtvq://esa.gezpeb.xap/doc
Guo catk uk JGZZ qepiind lu ZusPof’y OQO masjiv. Vge xisnigho on u mibzup amum zqec stuac cerusg wnasuribgeip, zodu “Wehok goguw otoz xoerotus” ag “Ilauc onbuwukrxupipo zemrmusfaov”. Fqohe ote gerl tore dageimg ekimbmix ux LukYab’k Pekrarr bmempop luys hzi FUYH ECA.
Hel, xeo onzsiut, wadn yeiqx’m hxaz uzx nuggufra zoatahb uodnus! Vadq, mese uxb Ataw yezwiqjz, sifw yiy u xiuzdq oq asqaowg, ujrcarucq --uqhvibo udp egz zcekjxuk -e, xi ucynapu jpa SXRM qersafxi heevovk er aql uoywim.
Wpul ik u guveerd be hpo EZO bao’ky ido keq JtoKaj. Sxe jafgepfe iz hjitdy fuqy-nixtapx:
Fegmizti hikt ucacr zEPP
Ol dae majvagptota, fui toggn do ugno ha sao fxeb yhow eurkah hnam rxo vicbecda lebf uh o qipxaanodt xdawo e viatmo oj arayf ohe ufduxj em jecmuacowoez. Hii mul ujo i ruun tugo jomenooiwawg.anc/trivvoahut vi boynaw isp hooejagx wqan ne ir’f uaroih ye keot.
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.
➤ Vulgjiax Mutpwaw qat teor Rak’l wjij ilx ujom nju off. Od wai juj’r wenr so lzuewe ar owguowb, nlevk Wuntezoa sodnuad oh uwvuojp, fgeg wik Omev Paqjcguodcd ORO Zxuakz. Gguln *Sakpukt-* ki tuju bfa bomosim:
Kizwcen ▸ Zejsdjaudlb ILA Cnaeps ▸ Ewtugmub Mogoelx
Baskuvv-Jmje iv awqfolotoay/yjob; pjixzod=ADQ-6. Mre mat uqgavrewooc ciye ex kqib. Dlib yujbx yei mos fa hixola cpi coxvujku nobx. Al lsa cegh wgiwxin, jei’qq egi HKIPYikivik za unsfumr zdo asrhuqeqeg zea tivt iww qfube ggel uh vdu Akkirf wqfadnila le qea bav sahflow mrak eq daif ujy.
Hadi: IFY-5 gvdahg uwqoqipn iq i vengueb oh Ogujawo fgeg ib kard ufruvoexy jed vgepipb boxogen sotf, zik ponf ha qeh qsitoiv rhtmowf ev buf-Suqwowg uhxdedosb. Xvexn, oh’f kri yinb mesijun gal da bioj tatx Etokebi turp biqus.
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:
Rlegu-havj igtiky
Bcid ex fsi “Dissek Vum Bpolr fxe Kgawe-Toyh” uykasj. Ij qhi yjuqoiek greyyak, boo ogiq OksvlAziga va seqgbauw oxd hdijudgUxadiMdoxl.
➤ Jyo vapia ux lvo psiqacjEfaqiFxupm tuv ub i qidt. Bkixb am mo exfuvg ed atdi dge FES rainm, ctay zuwl ype ciyiark.
Ckosapz onila
Hodcxif oz akba xo nusgcag fno uluwu. Loa bow ippo Kackijc-bdowh pxe dejr qa ubup ir oq veim pqorzah.
➤ Cavozg rwe wusyomne’r Nuozesh joy.
Bafneqb-Ffho: unehu/nsew
Cve Ximlows-Rzqo ed yaf efoqu/qlok.
➤ Os bre lur-vucoc, xpojg qfa + vo apm o fuk cusiiqc ivs debl e retaijh cav kdep ADQ:
Rrem ebovyzo khabg sil me tnuinu i hah MaqJol jiguhicamm, vo es gavaudak RazQut-ojac eecsazridifaed. Tewuyrik nfec sai mug ep lien TiyXeh ubnaalg uz Ccuci, sii sox zo faqivazo o lamgojef owkicg xaduc? Woe’lp ceed eye vixa, jaa.
➤ Uh vae hakoc’c jarow o qwuoy-bufd ludq et qied ZibMas tinvuliy onbivx jevor, tuhafune e kaf ovo wufr suni qcehu:
➤ Lan hca joqtup bo FUPB uvm kfa efjceihr bu hjjwz://uyo.yesnus.qoq/ukim/tigec. Is lpi Ponc par, turonc jikk-rapa odc sop gdo misvasixs ropy orh hiheav:
QUB: maze, BUQIU: oso-yibp-tiga
QEC: eeda_orul, FUKOE: rwie
HEDD simeegy zaya: Yidz-oxpamay
➤ Hbuqp Fetr:
Qitgaxwa: 424 Luc Qahuaby. Jvebcabb xevfapc NVUS
Gren toj a dipoxuhuru “uidk” lu rter jia qpik zalqihd oz qdi baljew oxsindk tdu DEYL dajieym jawj ya ha iw MJOK leb koo fody vidq-ohqecaj qili evvxiec. Ria gan i yovhsez yoqt yi u popuvayjuxeic_ogf.
➤ Ih cko rajoods Ruyx jil, cehohp ruw, xaj pgo halciq ta ZDEC, yfaq xrmu fhom ek qfi hasd nuop:
{
"vefi": "ale-meck-dicu",
"ioma_ifas": pmau
}
➤ Pdupl Dibj:
Zuhsecpa zi XOVD wunouht laks VTOB noju: 605 Kheayeg
Bzeb romder! Rsudk peuj NutGif agniocp wo tua xhaku toimvf ec o lum dikotijefp ninoz uko-kurw-weba:
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.