Date post: | 15-Jan-2015 |
Category: |
Technology |
Upload: | thimo-jansen |
View: | 2,648 times |
Download: | 0 times |
Of REST and BeansDoor Thimo Jansen
Introductie
* Thimo Jansen
* IBM Domino web developer
* http://www.thimojansenit.nl
Agenda
* REST
* JSON
* Architectuur
* Demo
* Code
REST
REST // Definitie
Representational State Transfer
A set of recommended architectural constraints in order for a system to be described as RESTful
Door Roy Fielding, ook HTTP 1.0 en 1.1
REST // Constraints
* Client - Server
* Stateless
* Cacheable
* Layered system
* Code on demand
* Uniform interface
REST // Communicatie
Data uitwisseling
Client doet weergave
Server doet opslag
REST // Communicatie
Via HTTP
* GET - Ophalen
* POST - Aanmaken
* PUT - Vervangen
* DELETE - Verwijderen
Lijkt op CRUD
JSON
JSON // Definitie
JavaScript Object Notation
* lightweight text-data interchange
* taal onafhankelijk
* "self-describing", easy to understand
JSON // Voorbeeld
Object:
{
"firstName":"John",
"lastName":"Doe"
}
JSON // Voorbeeld
Array:
[
100, 200, 300
]
JSON // Voorbeeld
Array met twee objecten:
[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Hello", "lastName":"World"}
]
JSON // Voorbeeld
Object met arrays en objecten:
{
"event":"XPages & Beer",
"location":"Houten",
"speakers" : [
{"firstName":"Tom", "lastName":"Steenbergen"},
{"firstName":"Thimo", "lastName":"Jansen"},
{"firstName":"Erik", "lastName":"van der Arend"}
]
}
(Syntax: http://www.json.org/, JSON Validator: http://jsonlint.com/)
JSON // Conversie
Javascript -> JSON
XPages: toJson(myObject);
Browser: JSON.stringify(myObject);
JSON // Conversie
JSON -> Javascript
var myJSON = '{"firstName":"John", "lastName":"Doe"}';
XPages: fromJson(myJSON);
Browser: JSON.parse(myJSON);
JSON // Conversie
Test of iets JSON is
XPages: isJson('{<some JSON string>}');
JSON vs REST
JSON != Hypermedia
JSON != REST
Ja, en?
http://norestforjson.blogspot.nl/2012/08/json-is-not-restful.htmlhttp://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
Architectuur
Architectuur // HTML
Browser
Web server
Request GET/POST
Response HTML
Application logic (SSJS, Beans)
Architectuur // REST
Browser
Web server
Request GET/POST
Response HTML
Application logic (SSJS, Beans)
AJAX Request GET/POST/PUT/DELETE
Response JSON
Architectuur // REST
Browser
Web server
Request GET/POST
Response HTML
Application logic
AJAX Request GET/POST/PUT/DELETE
Response JSON
Web server
Application logic
Demo
Code