RESTful Architecture is effectively an implementation of Resource-Oriented architecture (ROA). ROA - is a good fit for Service oriented Architecture (SOA) implementation. Check out KickStartPros approach on RESTful API Design.
* REST = REpresentational State Transfer
* REST is Resource Based Representation. REST identifies things by JSON or XML & URIs.
* REST behavior/actions are identified by HTTP methods (GET, POST, PUT, DELETE).
* Using Uniform Interface Architecture with REST you can decouple Client (like Browser/Android App/iOS App) and Server.
* REST using Layered System and Cacheable Architecture gives better performance.
5. What is REST?
• REST = REpresentational State Transfer
• Architectural Constraints
– Client-Server
– Uniform Interface
– Stateless
– Cacheable
– Layered System
– Code on demand
6. REST - Resource Based
REST
• Nouns, Not Verbs
• Things are identified by
URIs
• Person, User, Address
resource
• HTTP Verb to dictate the
operation on that resource.
• Multiple URIs pointing to
same resource.
SOAP - RPC
• Verbs or Actions.
• RPC calls (Don’t do this in
REST)
– getUserData
– getAllUsers
– searchUsers
– getUserAddress
– updateUserAddress
– deleteUser
7. Representations
• Represent part of the
resource state.
• JSON or XML
• Example: Buy a car
– Resource: Car (Audi A1)
– Service: Buy (POST)
– Representation:
• Name, Model, Price
• JSON or XML format.
8. REST API Design
Different REST Clients
iPhone App
Browser/
Web
Android App DELETE
PUT
GET
POST
CUSTOM
Params
Http
Methods
Your App Server
Load balanced
App
Server 1
App
Server
App
Server
App
Server
1…n
KickStartPros.com
Http/s
JSON/XML
JSON/XML
JSON/XML
9. HTTP Methods & Status Codes
• GET
• HEAD
• POST
• PUT
• DELETE
• TRACE
• OPTIONS
• 2xx Success
– 200 Ok
– 204 No Content
• 3xx Redirect
– 304 Not Modified
• 4xx Client Error
– 400 Bad Request
– 401 Unauthorized
– 403 Forbidden
– 404 Not Found
• 5xx Server Error
– 500 Internal Server Error
10. Keep Http/s Simple
• Resources – URI format
– Collection Resources (/users)
– Instance Resources (/users/ayl23d)
• Behavior
– Use Http Methods => CURD Database/Server Actions
– POST => Create
– GET => Read
– PUT => Update
– DELETE => Delete
– HEAD => Headers, no body
• Media types
– application/json
– application/xml
11. Post for Create
POST /users
{
“name” : “Kiran”
}
Response:
201 Created
Location:
http://www.kickstartpros.com/users/gdk23
12. Put for Update
PUT /users/<userId>
PUT /users/gdk23
{
“name” : “Devi Kiran”
“description”: “Trainer”
}
13. Post for Update
POST /users/<userId>
POST /users/gdk23
{
“name”: “Devi Kiran”
}
(Partial update or Full update)
Response:
200 OK
15. Client and Server
• Uniform Interface Decouples Client and
Server
• Design – http and URIs
– HTTP verbs (GET, PUT, POST, DELETE)
– URIs
– HTTP response
• Status
• Body
16. Uniform interface
• The uniform interface decouples client and
Server
– Identification of resources
– Manipulation of resources through these
representations
– Self-descriptive messages
17. HATEOAS
• Hypermedia as the engine of application state
• Client to Server
– Body Content
– URI and Query String parameters
– Request Headers
• Server
– Body Content
– Response Codes
– Response Headers
18. Stateless
• No client state at server.
• Any State is maintained
at Client side.
• Each request has all the
information to process
the request.
Client
1
Client
2
Client
3
Servers
19. More …
• Layered System
– A client cannot tell
whether it is connected
directly to the server.
– Load balanced Servers
– More Performance
• Cacheable
– Implicit
– Explicit
21. Example URIs
• GMail Rest API (v1 Reference by resource
type)
• Custom REST API from Yahoo
– https://developer.yahoo.com/yql/console/
– Example: get san francisco geo data:
select * from geo.places where text=“san francisco,
ca”
22. UI Data binding of REST API
• JQuery – Ajax calls
• Data Binding JS libs that help to bind with REST
response
– JQuery UI – Widgets
– Knockout – Model-View-ViewModel (MVVM)
– Angular JS – MVVM & MVC
– Backbone.js – RESTful JSON interface
– Ember.js – Template language, MVC and a router
– Kendo UI – MVVM
– Extjs – MVC (Model View Controller) & widgets
23. Summary & Reference
• JSON & REST Architecture
• Resource based REST API = Micro Services (SOA)
• REST API & Examples with JS libs
• Reference – Wiki
• contact@kickstartpros.com
– Join our trainings.
– Kick Start your project with us.