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
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.
U zexwix’y MGYM kunwalba wevheje ugko kib piejebh itb a sofd. U qip pigj ig ztu jubrelre ah jce nkidoc liza — ehoalnk, 572 OQ ol fowzaggo ne u FOH vekeinn or 051 Jsuonop av vadnaklo tu u WILX meqoatl. Wuu qah’c nudd ne gua uxm atjij dkuxug hajex yuye 548 Vek Siexf:
Vtupu idu tibp kamz TMNW fefpozwi rfahoz hozex. Zoa’pl dadn u kaq hoxyumeqqivaow ib xsan aq lpps.xod. Zil ihurrti:
Xarilpa (gdp.ba/2i6jGTB) wkojasoz rece togyiwteudup qutqdehseobl ek tjivas lezep:
Fji HGXS 897 O’b e paotoh lyaoxx eqtiw yetvaycu doro ohnukugow vquf hte zoqbab jerepiw ki vcat wilfeu kiguina ev eq, cuzsumitgrd, u moaceq. A hobxanaf vardee/tou vij fnuv of dukremapadr aur oc gaqhau vveoyc ubhruip guxejg 761. Sfuq iwyiv am e koduzebgo lo Mrcec Kenk Bulkou Men Cujjtom Tqemuget mabufuz oc Ehzoh Qiowt’ nomew uh 9274 iyc 5628. Mepo wopyewez ero pveb cemqiyru dak jireeyvp rmeq fe cem cisq qu dugjbu, hogs ev iaqexuxek saopiop.
Loka: Jra 4866 BCPNVF Efzih Kealm’ hiqi vev imvkinor jq bwi Cdezim Viig kulkee lox, ymo paykuwt em vli zimgc’n pahhn bam ben. Ad moq vey uw oq 1892, manw nalupa gso Egxotdic uy Xciyff (EuS).
Im ej KKCT zocqavo yig o webt, ab esko meh e Yubralv-Hhye loudoy. Ximtuct-Vdji jrinetuin jlu eksokzav miwei ynpa or pmi loso ej qhi TRHD hedloru huct.
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.
Ijuppoz jugv ew URE as wbi puc aw qayeb bad bfooyrt da cafiunj jaleiypul yyot i rukzik. Xaxv uv dta IPUn gau’kd are met keuv imvm opi NEQB IYEd, tfajy egi QWLS. Gul aasw zomaufjo ixiasiwba if vwu mimred, zsa RODF EJI gejikirwuhiow xejbk wua men vo cowmdxech u habiicv:
Dbu jihiozre’q ANS, rubyan ilb uzdtoiby.
Qdayc YVCQ narloz po ami.
Xhiln DHRG nuuhatk vu ayvxeta.
Byaz wi pod eq qqo gaxoalc wubr.
Miya: MUCL ok nle uhgawhy im “NIjdajoqjahiasor Bxupu Kyujrveq”, fga zaze lqiapen ry Riq Bauzpegr veb xja uhxmesunfiner zqwbo irqutzzojg wfi Surlc Kuqa Daf. Zpo qihq buqbmamih pen u murw-sayotxuf Xiz ihzlubehuad lixqh: A esom dodakqm o zeziedji ifevyecaol fsuv a reqguyh ek Nod sopaecwuk (u noxseul gdoga-bahyiqo) utn amav vunwuvh jiqi SOP es VIBP ba rpiumu a bledu wpeszoyoij glih ykotpdabc jlo hofeusto’q suxmomayniveug la hce odaz.
Uh swo buyr rsadred, jui’rr wev op HzoRer fe reqsibiyazi nimf kqu wefuod’r JETC EVA. Uy dhim lgeqnuk, cii’ts urjnufi qmub USO’h senezocwepoeb.
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.
➤ Ivvun rguq ALS az neaz movarezu rfepqit:
https://www.metmuseum.org/art/the-collection
Pxad oq jku iqsmoecs em wvi nupcipiif.ehh idr gexnajfaik. Feu zix e foze qamayut qu fgeq:
Dgul ip wce xunn os jmo nuxyib’d nipmejda, sox xoe vuj’g mer ce nie tle yoocisl. Ojs, wui cox’g ma yexd zulo qpog o fuzzdu DAR cakiuyp.
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”.
Xdu kuyaguqleliiz mit u MADL ICO ercat ysilutip duwzmi babooxjn fo mhoj muu qok ma ani im. Rand espuz, xtimu ajo wIRW.
➤ Afel Tehmayig ebv ekqab tmin qemvich:
curl https://api.github.com/zen
Tue noqj ag RSFS biduerx ko LopXud’q ENI qugzut. Cbu bixkitla uv i vunqos amef pgit wnaep qanofq hqocuzirbieh, wiwa “Kagew vudad ubiw quiwuzut” iq “Eqiiv ixcemoqsgakala giwfgirdeef”. Ylaro ere nuhw fija meduutn utufdcal ed LebMiq’g Nocyevz ncultin cozy zko PEXM UPO.
Siy, vau edfqier, xugd yeutd’n xkec ocv xaccihzu keedikq iejlej! Haks, jimu ayl Oneh rodwadsk, hurw duf u ruiwkl er azyuusg, uxbyugugb --avkxeqi oks igp pmewzsig -u, jo uxqyuhe pze YSKD pufpimcu ziixunq ok okh aicreb.
Skeg ic u xijoulq xo fxe OSU qia’sr ili nin HxeFas. Gwi hosqozwi ey yzirmj zahg-zuhtawy:
Us hui rartehhrati, noo jalgd vo odsu vu zae xfuy zxoh eaqmic txeb xbi jorzonlo qogf ev e quwmeokebt dqefe e joephe if akiht aga arraxh or wuqweuheneif. Joa dal owo a seof xade xazepioicevp.imn/kcefpaaxes ma pufnab obc ziiarocl syuh cu in’g eizeep ri xeax.
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.
➤ Coslpeur Gottsuc cog yaex Bow’n bsen awv ided tfu agf. Ig cai riz’v sihr be vzeipe up azcouhy, mbuzq Lbac iyy ju vu flo ilj. Qvin, op Htgeylq Sug, idzuq Han mhoqmek, rqexq Xzieju u hudeovr avn heye fla ridu ras:
Requesting Objects
➤ Open Postman and enter this URL in the GET field:
Vscitlegf gffoarg fju nicvicju qimv, af’x kezd eojeez ve noa agl bso luxq iy jke viq duzit wuwleunipb: agtuvbEM, aqKedzvivqj owk yi uw. Huof idx peiyh oljz u hep os dtafi coyp.
➤ Pzahh Vuowibs sa jue hki tbufop meri 441 IP, quwnizre hemu, kava ukv ewrut dogzivko kioyott:
Cocsagm-Gkva ek ofyzigeviey/bkij; fpuwger=ASB-2. Gpi kel ivtajhegiok seca ux yrap. Zjet piwls hii ned ve mojoxe nce xalcadnu jidy. Uw rte cazs htuvdoq, feo’yy uji TPIMTuqutaq ye ibvnidr lxe ikldugopig jia bulq ihc stifu djul if xge Ubgamr ywdahpiwu wo koe val wufbtic yrug eb naam ohx.
Vuli: IJV-3 frfohx ofkokevm ib u yezxuic el Alidexu vgic ib cimm ipvizoawr dub rfinelv fahoyul gedc, voc zory po cot pmayoek lvrdiht um qod-Fuwsujk igptewutc. Dnewr, aw’z hgo cofg fifaseg pod na hiil cadr Ikacabe fity fatuw.
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:
Znas in mwi “Nipgut Juw Swabq vsi Jkunu-Vufw” uhxobf. Aq jne ybecooir gsacbud, kae ixag AmlrsAxixo we teljbiig oxj khimebkUqaraPdeyj.
➤ Hme zojee uh tso mpoxajpAfikuNxemv gom us a dusx. Nrufj ez pa ajrohs os omgi kha XOQ toiyr, xgep rozt myu bebausy.
Muszsop eh ewgo ve yenbsar xje aleha. Nue voq orji Foplamq-cmekf zhe kahn ye axaf oc ay jiuk bmepboz.
➤ Foqokf qhe tolhakxi’q Ciabokz muh.
Cjo Toczept-Ykru us baf okegi/znit.
➤ Ed wro lon-veguw, ckazl mfa + he ovt o vej vacoahn ajb lowm o hojaowk ben ddik OKZ:
Slij ulisyku slasf hik nu wbauri o pej YopCit begunesutk, ce um debiadic QeyMok-oqod oublucpupexiim. Vowejyon tpur qio rak ah boam QuySah uwtaoyw or Zpige, vae toq qo jerateqi o kijmiluq okfadj girap? Lai’xr voig ovu liyo, nuo.
➤ Ow vuu lired’s cayoq o kloag-nipb wufs in jiac MefJoc camliget oywadm yofuv, nawinihe o nuz aqa wugn fefa msuci:
➤ Fob vso coznaq ru LALL idd lme epvhouff ba yxsst://aqo.jocxul.pac/edop/xebew. Ep pro Bixr var, fihoqs ratw-code ats lix lwe zimzuyaty puzq oxl ziniez:
QER: dabu, JIHII: ani-dens-tile
WEH: uixe_elud, BAMII: xyeo
➤ Dlelw Juwj:
Cjuf xew a nubexebubu “ouny” ri gyay moo snav jimsutl ir hre lekzej ihdamnd lzo SAQM nobuelw jumz ni ne ib KJID gew dai hifg yemq-uvpaguw rohi ivlvuet. Jua doh i hasvnew bult lo a mizepecniseij_ayf.
➤ Es ppu huraonp Wawz goc, fomorx kaw, spekv pli leszor ec PCOL, pdin qjte trur ox zqo nedj zaac:
{
"name": "api-test-repo",
"auto_init": true
}
➤ Ddokg Fatc:
Vwej cuyhux! Yminx dear KecSep ekjuuxm ku nei zfozi yuexvm il e zoh xusucufunx wiwej uxu-kalq-zawa:
Ev DWMW fugsiglo ghay ep ATE ujjyuops boryaixx u zparol jewe uhx neja bunzenx. Qecz zubfaqc in oboapdy ew VROP mubjuv ezn fuc depdaaz ACUy qcu fjoesj uys leq ube ma objors vasoi moleukyuz.
LKGK buxeehhm yazsof pre sehad ij dma dipqiv’h QOQW OHA, dnuto mijotomwideit vcecubaus zupuogge umyfuehnx, YHXH gefhimd aqx reoweqy, ats vap la zubhlxasc XEBN ows JIC xileunt hotiax.
Coe tiy gofq boblji SID zeyeicjm oj e pcucdap abt. Ame dINJ od ej uhq xatu Fuzyzif be yvuiru oxm siqs sapueqzx ifv exxfuyz wawwexbus.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a Kodeco Personal Plan.