Urnik 09.00 – 10.30 REST JSON odjemalci 10.30 – 11.00 odmor 11.00 – 12.30 avtentikacija strežniki orodja
Songsterr
REpresentational State Transfer arhitektura www prenosni medij = http ukazi = http ukazi podatki = URL + http telo [json,xml] kontrolne informacije = http header napake = http status
CRUD REST SQL Create POST [PUT] INSERT Read GET SELECT Update PUT [PATCH] UPDATE Delete DELETE
Podatki URL fizični strežnik + REST strežnik [API] + resource + parametri http://www.songsterr.com /a/ra/ songs/byartists.json ?artists=Queen ID je lahko del sredstva http://server/api/people/123/update?age=28
Http standardi Upoštevanje statusov 301 => preusmeritev Upoštevanje standardov [http headerji] Vmesni pomnilniki (cache proxy) Tip podatkov (accept, content-type) Nabor znakov (accept-charset)
Zakaj REST? Enostavna implementacija Berljivost http nivo obstaja povsod IoT JavaScript Berljivost Izraba spletne infrastructure Strežniki, proxy strežniki, firewalli Razširjenost strežnikov Facebook, Twitter, Google, Amazon, Dropbox …
Hypermedia as the Engine of Application State GET /account/12345 <?xml version="1.0"?> <account> <account_number>12345</account_number> <balance currency="usd">100.00</balance> <link rel="deposit" href="http://somebank/account/12345/deposit" /> <link rel="withdraw" href="http://somebank/account/12345/withdraw" /> <link rel="transfer" href="http://somebank/account/12345/transfer" /> <link rel="close" href="http://somebank/account/12345/close" /> </account>
Hypermedia as the Engine of Application State GET /account/12345 <?xml version="1.0"?> <account> <account_number>12345</account_number> <balance currency="usd">-25.00</balance> <link rel="deposit" href="http://somebank/account/12345/deposit" /> </account>
JavaScript Object Notation key:value, key:value, …. key:value { "person" : { "id" : 123, "name" : "Alice", "age" : Null, "friends" : [42, 177, 13] } }
JSON in Delphi System.JSON [XE6] REST.Json [XE6] TJSONValue, TJSONObject, … REST.Json [XE6] Tjson.ObjectToJsonString TJson.JsonToObject
Odjemalci http REST Client Library [XE5] DataSnap ICS, Indy, WinINet, System.Net.HttpClient REST Client Library [XE5] REST.Client, REST.HttpClient, REST.Authenticator.* … DataSnap TDSRESTConnection [D10] System.Net.HttpClient
JSON → DataSet TRESTResponseDatasetAdapter
Avtentikacija Simple [TSimpleAuthenticator] GET/POST, nešifrirano Basic [THTTPBasicAuthenticator] RFC2617 Header, BASE64 OAuth 1.0a [TOAuth1Authenticator] gesla se ne prenašajo zastarel OAuth2 [TOAuth2Authenticator] večina »velikih« (Facebook, Google …)
OAuth2 odjemalec http spletni strežnik Resource Owner Authorization An Overview of OAuth2 using the REST Client Components http://embt.co/blog-oauth2 odjemalec http spletni strežnik 1) Authorization Request Resource Owner 2) Authorization Grant 3) Authorization Grant Authorization Server 4) Access Token 5) Access Token Resource Server 6) Protected Resource
Strežniki DataSnap www Indy, ICS ORM mORMot
DataSnap XE Enterprise+ Win32/64 VCL/FireMonkey Odjemalci RAD Studio: Win32/64, OS X/32, iOS, Android Proxy: Android, BlackBerry, iOS, Windows Phone JavaScript: brskalniki, naprave REST: karkoli
DataSet → JSON TDataSetRESTRequestAdapter github: andrea-magni/TDataSetRESTRequestAdapter
Orodja REST Debugger XE5, source Postman Chrome Fiddler .NET 2/4
Vprašanja?