Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JSON, XML, SOAP, REST

JSON, XML, SOAP, REST

JSON and XML data formats explanation.
Comparison of REST and SOAP services, examples and explanation.
Lietuviškai aprašyti JSON ir XML duomenų formatai. Pateikiamas palyginimas tarp REST ir SOAP komunikavimo su serveriu protokolai.

Avatar for Nerijus Eimanavičius

Nerijus Eimanavičius

April 03, 2012
Tweet

Other Decks in Programming

Transcript

  1. www.telesoftas.com TeleSoftas JSON, XML, SOAP, REST Nerijus Eiman Nerijus Eimana

    avičius vičius Server side specialist Server side specialist nerijus@eimanavi nerijus@eimanavicius.lt cius.lt
  2. www.telesoftas.com JSON • JSON tai JavaScript Object Notation • JSON

    yra lengvas tekstinės inform. apsikeitimo formatas • JSON yra nepriklausomas nuo kalbos ar platformos • JSON yra lengvai suprantamas { "employees": [ { "name":"Vardenis Pavardenis" , "age":21 }, {"name":"Vardenytė Pavardenytė","age":18} ] } { "employees": [ { "name":"Vardenis Pavardenis" , "age":21 }, {"name":"Vardenytė Pavardenytė","age":18} ] }
  3. www.telesoftas.com JSON Sintaksės Taisyklės • Informacija aprašoma vardo ir reikšmės

    pora • Informacija atskiriama kableliais • Riestiniai skliaustai reiškia objektus • Laužtiniai skliaustai reiškia masyvus JSON Failai Plėtinys ".json" MIME "application/json" JSON Failai Plėtinys ".json" MIME "application/json"
  4. www.telesoftas.com JSON Reikšmių Tipai • Skaičius (sveikas ar racionalusis skaičius)

    123 arba 0.123 • Tekstas (dvigubose kabutėse) "tekstas" • Loginė reikšmė (true arba false) • Masyvas (laužtiniuose skliaustuose) [] • Objektas (riestiniuose skliaustuose) {} • null JSON Failai Plėtinys ".json" MIME "application/json" JSON Failai Plėtinys ".json" MIME "application/json"
  5. www.telesoftas.com XML • XML tai eXtensible Markup Language • XML

    žymėjimas labai panašus į HTML • XML žymes (tags) gali sugalvoti pats • XML sukurtas perduoti ir saugoti informacijai • XML yra nepriklausomas nuo kalbos ar platformos • XML svarbu mokėti ir lengva išmokti <?xml version="1.0" encoding="utf-8"?> <note> <to>Vardenis</to> <from>Pavardenė</from> <heading>Priminimas</heading> <body>Prisimink mane šį savaitgalį!</body> </note> <?xml version="1.0" encoding="utf-8"?> <note> <to>Vardenis</to> <from>Pavardenė</from> <heading>Priminimas</heading> <body>Prisimink mane šį savaitgalį!</body> </note>
  6. www.telesoftas.com XML Sintaksės Taisyklės • Visi XML elementai privalo turėti

    baigiamąją žymę • XML žymių vardams turi įtakos raidžių dydžiai • XML elementai privalo būti tinkamai sudėti • XML dokumentai privalo turėti šakninę žymę • XML atributų reikšmės privalo būti kabutėse XML Failai Plėtinys ".xml" MIME "application/xml" "text/xml" XML Failai Plėtinys ".xml" MIME "application/xml" "text/xml"
  7. www.telesoftas.com XML Elementas gali savyje laikyti • Kitus elementus •

    Tekstą • Atributus • Arba visu anksčiau minėtų mišinį XML Failai Plėtinys ".xml" MIME "application/xml" "text/xml" XML Failai Plėtinys ".xml" MIME "application/xml" "text/xml"
  8. www.telesoftas.com XPath • XPath is a syntax for defining parts

    of an XML document • XPath uses path expressions to navigate in XML documents • XPath contains a library of standard functions • XPath is a major element in XSLT • http://www.w3schools.com/xpath/
  9. www.telesoftas.com CRUD • CRUD tai Create, Read, Update, Delete •

    CRUD yra svarbių operacijų rinkinys, IS sistemoms • Kiekviena CRUD operacija turi atitikmenis SQL Operacija SQL HTTP/REST SOAP/XML-RPC Create (kurti) INSERT POST POST Read (skaityti) SELECT GET POST Update (atnaujinti) UPDATE PUT POST Delete (ištrnti) DELETE DELETE POST
  10. www.telesoftas.com CRUD taip pat naudojamas aprašyti vartotojo sasają C sukurti

    ar pridėti naują įrašą R skaityti, gauti, ieškoti ar peržiūrėti esamus įrašus U atnaujinti ar taisyti esamus įrašus D ištrinti ar deaktyvuoti esamus įrašus CRUD nėra laikoma kaip architektūrinis sprendimas, tai daugiau sistemos pilnumo nusakymo kriterijus. CRUD nėra laikoma kaip architektūrinis sprendimas, tai daugiau sistemos pilnumo nusakymo kriterijus.
  11. www.telesoftas.com SOAP • SOAP tai Simple Object Access Protocol •

    SOAP - XML žinutėmis paremtas bendravimo protokolas • SOAP pirmtakas yra XML-RPC • SOAP objektai aprašomi WSDL failuose (*.xsd) • SOAP užklausos žinutės tik XML formatu • SOAP atsakymo žinutės tik XML formatu Plačiau apie SOAP technines detales: http://www.w3schools.com/soap/default.asp Plačiau apie SOAP technines detales: http://www.w3schools.com/soap/default.asp
  12. www.telesoftas.com SOAP užklausos pavyzdinė žinutė POST /InStock HTTP/1.1 Host: www.example.org

    Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" > <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope> POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" > <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
  13. www.telesoftas.com SOAP atsakymo pavyzdinė žinutė HTTP/1.1 200 OK Content-Type: application/soap+xml;

    charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" > <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPriceResponse> <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" > <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPriceResponse> <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap:Body> </soap:Envelope>
  14. www.telesoftas.com REST • REST tai REpresentational State Transfer • REST

    tai architektūros stilius paremtas HTTP protokolu • REST išnaudoja gerai žinomą ir aprašytą protokolą • REST servisu vyksta įprastais HTTP metodais • REST užklausos duomenys adrese arba užklausos kūne • REST gali atsakyti įvairiais formatais pvz. JSON, XML, ... Įvadas į REST: http://youtu.be/YCcAE2SCQ6k Praktiškasis REST: http://youtu.be/R8SIxZVaai4 http://youtu.be/QpAhXa12xvU Įvadas į REST: http://youtu.be/YCcAE2SCQ6k Praktiškasis REST: http://youtu.be/R8SIxZVaai4 http://youtu.be/QpAhXa12xvU
  15. www.telesoftas.com RESTful Web Service HTTP methods Resource GET PUT POST

    DELETE Collection URI /resources List the URIs and perhaps other details of the collection's members. Replace the entire collection with another collection. Create a new entry in the collection. The new entry's URL is assigned automatically and is usually returned by the operation. Delete the entire collection. Element URI /resources/<id> Retrieve a representation of the addressed member of the collection, expressed in an appropriate Internet media type. Replace the addressed member of the collection, or if it doesn't exist, create it. Treat the addressed member as a collection in its own right and create a new entry in it. Delete the addressed member of the collection.
  16. www.telesoftas.com REST užklausos pavyzdinė žinutė GET /lt/dots/594.json HTTP/1.1 Host: www.example.org

    Accept: application/json Accept-Language: en-US Accept-Charset: utf-8 GET /lt/dots/594.json HTTP/1.1 Host: www.example.org Accept: application/json Accept-Language: en-US Accept-Charset: utf-8
  17. www.telesoftas.com REST atsakymo pavyzdinė žinutė HTTP/1.1 200 OK Date: Thu,

    26 Apr 2012 00:01:01 GMT Content-Type: application/json; charset=utf-8 Content-Length: nnn { "id":278, "siteid":3, "lat":54.3920987413886, "lng":24.0508588577027, "type":269 "title":"Black and white" } HTTP/1.1 200 OK Date: Thu, 26 Apr 2012 00:01:01 GMT Content-Type: application/json; charset=utf-8 Content-Length: nnn { "id":278, "siteid":3, "lat":54.3920987413886, "lng":24.0508588577027, "type":269 "title":"Black and white" }
  18. www.telesoftas.com SOAP vs REST Detalus palyginimas: http://youtu.be/v3OMEAU_4HI Detalus palyginimas: http://youtu.be/v3OMEAU_4HI

    URL HTTP metodai POST GET INSERT UPDATE DELETE SELECT /articles/create /article /articles/update/<id> /articles/delete/<id> /article/<id> REST POST PUT DELETE GET /articles INSERT SELECT /articles/<id> UPDATE DELETE SELECT SOAP POST (action=insert) POST (action=update) POST (action=delete) POST (action=select) /articles INSERT UPDATE DELETE SELECT