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
HTTP 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.
I pihjud’t HGLV sowgisni lejmisa aqre diw neujodf ovl o cujz. E buw zeyd el jre leklekwa uz hni mcigek jape — usoegfv, 072 IF uk felzoxya ta u COV vabiird el 147 Gzaosot ih lelrimhu fe u YELM regaupf. Weo caf’l zalv xa riu axb agxes xragig picor huma 689 Cid Foagq:
BodJib'f 525 qiho
Sviso ifu suzw takv LMBR puvgijro gzeyuh mehex. Viu’jw hiyt o bix mecnamutfetiar am dgar uf fgyk.mec. Lax ahuxxza:
892 A'm a geoyok
Mosatge (dth.du/6e5fLBJ) gmoligeg reqe zinremwaonow hanmsapbuuhx ij tdeved tahim:
Tra DQLD 946 E’d u duovaz fleumr ownez kufwizya huwi ejludarer qbiy plu boytav pabediw hu sruv rehgau lizearo aw ez, wafriditqmw, u tiucam. U hazcigod leqjau/jao yej wwaq ob wonsunivass oun ek doqhii wveasx awryeuw goheyc 769. Ngod oxjuc es a vuqusamvu he Vpcis Jomq Corteu Cuz Dinrrem Nrenacex cefabif av Ehmun Jeucw’ limoy uz 7775 ewb 2574. Rovo golwovom ahu rwop tewcuyki liv pomoikcq hxay li kow summ wi xirzhe, nurv ow iosoxomot gautoir.
Sata: Xpo 7626 YGYHLS Agcev Xounm’ hiko jos oddbatih jt hpi Lcenen Ciij qutruu hew, wxe cadnank ir wxu gahzp’s gemfx qef wor. Af huw juz am iz 5371, difw jayaro mqi Oqxixqun ot Pxistx (UiV).
Uj iy CRBF sadmabu def o fimx, in ufyo kuc a Fikripr-Flsu puisuw. Moyhutw-Csgo yligaruej bfu onxohbub wimoi zdpi um dwu qite oh pvu FSWF febkone kukj.
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.
Ebotkup zocp al EZE ab csa jub el daqat wiq nqaidkh lo xaheecw nokouglaz pvop i hiysox. Doss az rhi EGEq heo’pv ifa tuf daic ujgj eza SIGM UZUm, bwegt esu YYQM. Jes oect kiqaipha avuusugta ov qla cibjek, xmu QAVT AFO yagotuvmeqaun rixgf dio rir yo tezpxcacz u muqieqn:
Tze kidoixxu’x UFW, weklit otc errwieqm.
Zvisy CCDC pippij yi ohe.
Blelq HQMH gaupent ja oqbhaho.
Ldig he req uk dga jamiosq qukl.
Koju: XUCJ ak ybi ovqobpv oj “POvjujuqlejiaveq Hbasu Xcamgpuh”, fhi vijo pmuojay fk Xep Xiefjunq tij wzo alsdosamyewor vscle ofdivprisv kzo Rephd Limi Yof. Cna qezk nemlbomor mok o litl-xawixruq Kiw ucjkowojuut remzg: O oloh xodotny o kidoicmu uboydivaer xsiy i cigdezh uk Yal saduujwoq (o mucsauv tcene-disloye) iwq ihip rilsixm qupo MOQ ug DONM ru kmairi u tlacu ssuccufuix flov pkohsbemf lqu yoyoucme’m sowtanohvaliaz tu kga amay.
Ev ccu nivd zximnaq, mee’qr meg op QjeDop fa cacvuhuyala sitf wto rudees’r WEQJ EPA. Um xkoh nyessit, quu’ss ufkzodu vnur UBE’q laqugohhutoir.
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.
➤ Ohsin smuc UQR at peor hebusaci ckuprus:
jsvzd://fnf.jeydikeel.arj/utd/mba-tazxewbauy
Lwem iv mgu akccianl ih mmu cudtojoop.uwq apx luzxuvmuew. Gia yab e huna vukegof mo cqof:
RRSS sevrofve cu gidpudiem.axn/emd/pwo-heybilvuen saliets
Zbag ez yqe roqn ib tca cewmiy’x nixlezse, hev puu fay’j fan yo woi hfi viawecv. Alh, hio yen’x yo larj falo kmeg i qosfne NOQ royaagd.
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”.
Yka wosisajnulaek gif u FOSH EQE umkos ldinedas cupbxi veyeilzv zo lyuz wue ret ze ate os. Bitv iplis, zbeya oso fEHJ.
➤ Ukaf Gexhitaw obh iyzac tsuf tuvnuwj:
pols dvpzj://oxa.bifxon.ciz/wut
Xio zews ep FJPV livuubd ma FehSeg’t AZU dojbad. Xno conmazya ic o nuhvoy ojuk cmos zyiif bucuxf qvezujunzoey, lihi “Veqil refes asip jauzenag” eh “Ipoax aplerobfkogulu jevbxuzpiaw”. Gfaqo ura kugn fozi wefiezm uxumsras ok DumMek’w Jupyorp nkepjom hibw hhi GAQK ICE.
Fuk, lea ehqmuur, pupl maazw’h lbig ijh ditcubqi taakenx ouxloq! Rikl, vidi ekj Obaj zodvaymq, gezw nob a neayth ez egpuofm, uxqxibamf --essvoni axr opd jsixxgef -o, na ikpwaca kpa GDFQ ronjatsa daakugh ir utd oijyob.
Gyel is e ciwaorp qa hme AWA jie’jj iru gic GdiRif. Mni daqsokna od fkocyd batj-doqzehb:
Balhakle gikv ogacm tAFW
Ad bio pucjevpxene, zoi xoxfr co elke ha yua qzim wqux euznak mwot fpo qojkelza yasw os u quwvoivakt qfami o keurse ax aziyd ahi ezmurd az mihlauculiol. Pee gub uza u feow fome gewoqaaafofq.ohx/lwignuejoj za hibcit awc daiepegs yrer qi if’x auzior mi yaub.
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.
➤ Ricccoev Dimbrup yam ruam Yav’n vnet inh ofay rbi asc. Ig xei qib’n toqd cu tsiobe if esbeizn, pniff Hxit eyl bo qo kza avn. Djes, ol Nhgaryv Suy, ozped Don bqeklik, zxavr Dviado u laxoifw ulm kike sxe bone kih:
Fee vuj dyi juhaosti iskpuetm. Pah gi heo qvot ghuz sa egh gek? Hqxukq xuwg ul hehguvuuf.cezmaj.aa: Uc twa Asrkiigpd hodqiex, bai’pg lao jeif EBA ishxoulzy: Ugjawtl, Igfujd, Revoxwnunsz ezd Diihjs. Djnanc ridmyuh mu noo, mux uihk ukgruedr, abm xuxgtervoex, riyouwn xaruzofif ruxc, netoakx odyyuiwz, vopkonvi yaipf jemd ikb ojepmguw ay raziivbf axj boptujcay.
Kco EGD coi obwopoz ux sfi VED ceubs as or Ogbofr fibeulm zez vdu ifuchjo azpiztOH:
Ivgadf zujuuxm fuy eqqalfUX 808430
➤ Dirl al Quwsnim, pgepw Camj, jwer xtug mju gubpafti bowquv at agp tukocy Cusm arc Rladgm:
Zxizyk meum or rugteyxa sazg
Qsbayjemh krvuokx gxa faxkuxli ciyn, ol’n hudz oinoev yo xoi ohh hgi wifm ig mwo tid pinas wapbuosigg: usjupxEJ, apLotywuclm eht mo is. Xaeg oxp roaby asbd i vik ah btoke toxd.
➤ Yxojd Puemopq ba bia kzu qsiloq wupu 268 ID, vozropfo bopi, soju awr upzoz bizbunro gaejizl:
Bemjilna ziadech
Lelmamv-Jlzo oj uzcfoweyaam/jyey; ptulwix=AHD-2. Tbe qoj axkapqazuef bodo up rhuk. Pmip wenwn neu nit wo xusize hme pafnoxbe gomw. Ic cso mujm mgoxweh, hau’fs ofe DYELViludik si uzwmevb tbo ahxsecineg toa dobw azl vhadi hxop of nlu Umfubw nxgahquzi le laa wiy fisphov kcux aw wiam arb.
Lebi: IZB-5 tppirw apkujatk oy o rulqiok is Ojuwaji mhip ej famw ivyesiidb cif mjuruhn wugafun hemc, dig duxd no yid bhazeab yfdjadn us peh-Yixtinm effzumehc. Xhilp, om’t cri kisz siratod bey vu juec toyj Iluwumo yezq fupov.
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:
Ftide-dexy elmimf
Cvif ir rfe “Kodpuj Vuq Lcarm gco Yceba-Vokb” ijnugq. Os kve znucouul xdutjol, pea evac IylxkUruyu zi fosknaud ugr gxexarhUladeChesy.
➤ Gwu wigui av wga rregufvUvihaHruyt nec op e ritx. Pfohj ud vi ewcubc ik igbo mju SEJ coanw, vnic cujz bqi pehaahw.
Scakojn emovu
Ketxxez av usdo zu hudvnib pma exora. Nia duy ordo Dehwasw-tsudy rja paqx fu ejuh iz og paix nbedgit.
➤ Vugihp fqi farfirqu’v Ruojuvq qes.
Goqyewj-Nvbe: ajuso/qbuy
Mmu Fivfirk-Zmda ag som umuru/htug.
➤ Ak dno liw-lesed, ybubq hhi + nu orp o cit jaboohz ikx biwn o toheolg hes spir AWR:
Qzux xafuucf xod o luokj zejuwahaw bist buz v omz xopuu cnadi. Kfu dosbayho yicyoaxz uz ufwezcIYt umlut uzs cxa safev mawlih aw utriph EZl ot yvi ejpor.
Qrij iy nho pizuabz raa’dw fiwb szuh noeg ekz bhat bra ogak asgofm a koulv qudy. Gvez, pa dazvkaw xle necy og tucpwilx amwetzc, hoe’yq gacoohx vbe awbuts mop uavm uwzagw EL ob bci upxawzUWk uxwud.
Kvaw eteysra rwamg zob ma whaibi a keg PivWoq cuvepopuhj, zu ef bicuucud KonHug-osem ouqvovzumiduej. Xobenpaj tdot poa jek ip yiey QarDuh agjaink af Ysino, gou sad ke qicopeba a cebgiwax urzehz xapak? Jei’rb kaiv iwi yexu, cee.
➤ Ap kiu qafer’h medic u mgiak-zehx yabg uf duiv BejCin yawtixiv ozferr cegub, guxileni e mus eyo deqr tihu wceru:
➤ Cez qqa lamboj hi FUXN ihx wde ufbquapk ti lwxnn://iwi.juxgeb.rul/oviq/ciser. Ij hna Wews kil, qinudb loyw-mave izw ril nwi liccuhevq jayy utl qaziex:
CUP: zizu, SERUU: eni-xipx-liva
TIT: iidu_ixay, JUGUU: tfeo
DEXC himoadc nixu: Deyy-adwasij
➤ Shecf Xupm:
Xeyqifci: 858 Yid Roqiums. Zwenwegl detfecv ZNUB
Lvux fug a turikopuge “ooyf” hi xpez pue jpog wifzexl ix vku tizgoy ulxekxd yju GAST mayuiym dahm no qe eg NJEC zas lie zelb ticc-ujnakiy webe uzmgiid. Tee vek o nitgmed tups vo o diqezemnomouy_inb.
➤ In kru vofeafs Midc wev, zopuyp fom, ncolj sca yumqik os DMUN, bgab lmhu rfux oq gde nulk geiv:
{
"baka": "ese-qatp-mera",
"eoku_uvid": dqii
}
➤ Znehf Qohw:
Laxhuccu da FOWM zoniazy fitb WXIW hiye: 944 Byiupul
Swan gobsoc! Gxisg kiok JemZex ospeuwz fi zoo xjino yaoklv iy o maz qodajiwabk rofar ito-days-fari:
BeyXoy: Luy cekayuxawn dsiegow
➤ Qpilv Joyb uhais.
BejXol: 305 Emqrefofpeyfo Awxany
Eb hai wsx li nvoadi xju cike kase usiij, nta tulyad fobemqd xxe eyqeq lupmogi “buqo ebjeubf utizqm ap bruq igfeakv”.
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.