SlideShare a Scribd company logo
1 of 20
Aslam Maududy Atturraby
Fiki Rieza
Fina Sabrina
Client Serve
r
GET /the-resource
...
200 OK
<html>Code...</html>
Displays the page,
then user clicks
on link.
GET /another-resource
...
200 OK
<html>Code...</html>
Displays the other
page, ...
The interface is built on HTML & HTTP.
 Drawbacks:
 The client must understand both HTTP and HTML.
 The entire webpage is replaced with another one.
 No way to animate transitions between webpages.
 Same data is usually sent in multiple responses.
 E.g. HTML code for the layout.
Client Serve
r
HTTP &
HTML
Client
???
• HTTP & HTML can be used, but is not optimal.
• The GUI on smartphones does not use HTML.
• E.g. GET /users/3:
<h1>Claire</h1>
<p>Claire is 24 years old and lives in Boston.</p>
Name
Age City
An API is an interface for Machine ↔ Machine communication.
 An API making use of HTTP is called a Web API.
A GUI is an interface for Human ↔ Machine communication.
Serve
r
Client
API GUI
User
 Remote Procedure Call, RPC.
 Clients can call functions on the server.
 Remote Method Invocation, RMI.
 Clients can call methods on objects on the server.
 Representational State Transfer, REST.
 Clients can apply CRUD operations on resources on the server.
An architectural style for distributed hypermedia systems described by Roy Thomas
Fielding in his doctoral dissertation 2000.
 Consists of constraints:
1. Client - Server
2. Stateless
3. Cache
4. Uniform Interface
5. Layered System
6. Code-On-Demand
Client Server Server
Relational
Database
Web
Applicatio
n
Web
Browser HTTP SQL
The name "Representational State Transfer" is intended to evoke an image of how a
well-designed Web application behaves: a network of web pages (a virtual state-
machine), where the user progresses through the application by selecting links (state
transitions), resulting in the next page (representing the next state of the application)
being transferred to the user and rendered for their use.
From Roy's dissertation.
Serve
r
Id Name
1 Alice
2 Bob
3 Claire
Users
Client GET /users/2
...
{"id": 2, "name": "Bob"}
Changes state.
{"id": 2,
"name": "Obi"}
PUT /users/2
{"id": 2, "name": "Obi"}
 Use URIs to identify resources.
 Use HTTP methods to specify operation:
 Create: POST (or PUT)
 Retrieve: GET
 Update: PUT (or PATCH)
 Delete: DELETE
 Use HTTP headers
Content-Type and Accept
to specify data format for the resources.
 Use HTTP status code to indicate success/failure.
Bad
POST /login
POST /create-book
GET /get-top-10-books
Good
POST /login-sessions
POST /books
GET /top-10-books
REST is an architectural style, not a specification.
 In practice, it can be used in many different ways.
 But some are better than others.
Good recommendations:
 Web API Design - Crafting Interfaces that Developers Love
 https://pages.apigee.com/rs/apigee/images/api-design-ebook-2012-03.pdf
A server with information about users.
 The GET method is used to retrieve resources.
 GET /users
 GET /users/2
 GET /users/pages/1
 GET /users/gender/female
 GET /users/age/18
 GET /users/???
 GET /users/2/name
 GET /users/2/pets
GET /users?page=1
GET /users?gender=female
GET /users?age=18
GET /users?gender=female&age=18
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 The GET method is used to retrieve resources.
 Which data format? Specified by the Accept header!
GET /users HTTP/1.1
Host: the-website.com
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 66
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
application/xml
was popular before
JSON.
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 The POST method is used to create resources.
 Which data format? Specified by the Accept and Content-Type header!
POST /users HTTP/1.1
Host: the-website.com
Accept: application/json
Content-Type: application/xml
Content-Length: 49
<user>
<name>Claire</name>
</user>
HTTP/1.1 201 Created
Location: /users/3
Content-Type: application/json
Content-Length: 28
{"id": 3, "name": "Claire"}
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 The PUT method is used to update an entire resource.
PUT /users/3 HTTP/1.1
Host: the-website.com
Content-Type: application/xml
Content-Length: 52
<user>
<id>3</id>
<name>Cecilia</name>
</user>
HTTP/1.1 204 No Content
PUT can also be used to
create a resource if you
know which URI it
should have in advance.
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 The DELETE method is used to delete a resource.
DELETE /users/2 HTTP/1.1
Host: the-website.com
HTTP/1.1 204 No Content
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 The PATCH method is used to update parts of a resource.
PATCH /users/1 HTTP/1.1
Host: the-website.com
Content-Type: application/xml
Content-Length: 37
<user>
<name>Amanda</human>
</user>
HTTP/1.1 204 No Content
The PATCH
method is only a
proposed
standard.
Id Name
1 Alice
2 Bob
3 Claire
Users
A server with information about users.
 What if something goes wrong?
 Use the HTTP status codes to indicate success/failure.
GET /users/999 HTTP/1.1
Host: the-website.com
Accept: application/json
HTTP/1.1 404 Not Found
• Read more about the different status codes at:
• http://www.restapitutorial.com/httpstatuscodes.html
• Optionally include error messages in the response body.
Id Name
1 Alice
2 Bob
3 Claire
Users
How should you think?
 Make it as easy as possible to use by other programmers.
Facebook:
 Always return 200 OK.
 GET /v2.7/{user-id}
 GET /v2.7/{post-id}
 GET /v2.7/{user-id}/friends
 GET /v2.7/{object-id}/likes
How should you think?
 Make it as easy as possible to use by other programmers.
Twitter:
 Only use GET and POST.
 GET /1.1/users/show.json?user_id=2244994945
 POST /1.1/favorites/destroy.json?id=243138128959913986

More Related Content

Similar to HTTP & HTML vs RESTful APIs

Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Sumy PHP User Grpoup
 
UserCentric Identity based Service Invocation
UserCentric Identity based Service InvocationUserCentric Identity based Service Invocation
UserCentric Identity based Service Invocationguestd5dde6
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developersMario Cardinal
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfRaghunathan52
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfRaghunathan52
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Restful webservices
Restful webservicesRestful webservices
Restful webservicesKong King
 
Authentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresAuthentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresCorley S.r.l.
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Tim Burks
 
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applicationsAn introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applicationsmrdon
 
E-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb AbdessattarE-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb AbdessattarAbdessattar Ettaieb
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAnuchit Chalothorn
 
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...Dataconomy Media
 

Similar to HTTP & HTML vs RESTful APIs (20)

Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
UserCentric Identity based Service Invocation
UserCentric Identity based Service InvocationUserCentric Identity based Service Invocation
UserCentric Identity based Service Invocation
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
HTTP fundamentals for developers
HTTP fundamentals for developersHTTP fundamentals for developers
HTTP fundamentals for developers
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
SCWCD : The web client model
SCWCD : The web client modelSCWCD : The web client model
SCWCD : The web client model
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
Authentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresAuthentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructures
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)
 
An introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applicationsAn introduction to Struts 2 and RESTful applications
An introduction to Struts 2 and RESTful applications
 
E-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb AbdessattarE-Services TP2 ISI by Ettaieb Abdessattar
E-Services TP2 ISI by Ettaieb Abdessattar
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
DN 2017 | Big Data / Microservice Versioning | Thomas Pötter | Compris Techno...
 
HTTP Basics Demo
HTTP Basics DemoHTTP Basics Demo
HTTP Basics Demo
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

HTTP & HTML vs RESTful APIs

  • 1. Aslam Maududy Atturraby Fiki Rieza Fina Sabrina
  • 2. Client Serve r GET /the-resource ... 200 OK <html>Code...</html> Displays the page, then user clicks on link. GET /another-resource ... 200 OK <html>Code...</html> Displays the other page, ...
  • 3. The interface is built on HTML & HTTP.  Drawbacks:  The client must understand both HTTP and HTML.  The entire webpage is replaced with another one.  No way to animate transitions between webpages.  Same data is usually sent in multiple responses.  E.g. HTML code for the layout.
  • 4. Client Serve r HTTP & HTML Client ??? • HTTP & HTML can be used, but is not optimal. • The GUI on smartphones does not use HTML. • E.g. GET /users/3: <h1>Claire</h1> <p>Claire is 24 years old and lives in Boston.</p> Name Age City
  • 5. An API is an interface for Machine ↔ Machine communication.  An API making use of HTTP is called a Web API. A GUI is an interface for Human ↔ Machine communication. Serve r Client API GUI User
  • 6.  Remote Procedure Call, RPC.  Clients can call functions on the server.  Remote Method Invocation, RMI.  Clients can call methods on objects on the server.  Representational State Transfer, REST.  Clients can apply CRUD operations on resources on the server.
  • 7. An architectural style for distributed hypermedia systems described by Roy Thomas Fielding in his doctoral dissertation 2000.  Consists of constraints: 1. Client - Server 2. Stateless 3. Cache 4. Uniform Interface 5. Layered System 6. Code-On-Demand Client Server Server Relational Database Web Applicatio n Web Browser HTTP SQL
  • 8. The name "Representational State Transfer" is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state- machine), where the user progresses through the application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use. From Roy's dissertation.
  • 9. Serve r Id Name 1 Alice 2 Bob 3 Claire Users Client GET /users/2 ... {"id": 2, "name": "Bob"} Changes state. {"id": 2, "name": "Obi"} PUT /users/2 {"id": 2, "name": "Obi"}
  • 10.  Use URIs to identify resources.  Use HTTP methods to specify operation:  Create: POST (or PUT)  Retrieve: GET  Update: PUT (or PATCH)  Delete: DELETE  Use HTTP headers Content-Type and Accept to specify data format for the resources.  Use HTTP status code to indicate success/failure. Bad POST /login POST /create-book GET /get-top-10-books Good POST /login-sessions POST /books GET /top-10-books
  • 11. REST is an architectural style, not a specification.  In practice, it can be used in many different ways.  But some are better than others. Good recommendations:  Web API Design - Crafting Interfaces that Developers Love  https://pages.apigee.com/rs/apigee/images/api-design-ebook-2012-03.pdf
  • 12. A server with information about users.  The GET method is used to retrieve resources.  GET /users  GET /users/2  GET /users/pages/1  GET /users/gender/female  GET /users/age/18  GET /users/???  GET /users/2/name  GET /users/2/pets GET /users?page=1 GET /users?gender=female GET /users?age=18 GET /users?gender=female&age=18 Id Name 1 Alice 2 Bob 3 Claire Users
  • 13. A server with information about users.  The GET method is used to retrieve resources.  Which data format? Specified by the Accept header! GET /users HTTP/1.1 Host: the-website.com Accept: application/json HTTP/1.1 200 OK Content-Type: application/json Content-Length: 66 [ {"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"} ] application/xml was popular before JSON. Id Name 1 Alice 2 Bob 3 Claire Users
  • 14. A server with information about users.  The POST method is used to create resources.  Which data format? Specified by the Accept and Content-Type header! POST /users HTTP/1.1 Host: the-website.com Accept: application/json Content-Type: application/xml Content-Length: 49 <user> <name>Claire</name> </user> HTTP/1.1 201 Created Location: /users/3 Content-Type: application/json Content-Length: 28 {"id": 3, "name": "Claire"} Id Name 1 Alice 2 Bob 3 Claire Users
  • 15. A server with information about users.  The PUT method is used to update an entire resource. PUT /users/3 HTTP/1.1 Host: the-website.com Content-Type: application/xml Content-Length: 52 <user> <id>3</id> <name>Cecilia</name> </user> HTTP/1.1 204 No Content PUT can also be used to create a resource if you know which URI it should have in advance. Id Name 1 Alice 2 Bob 3 Claire Users
  • 16. A server with information about users.  The DELETE method is used to delete a resource. DELETE /users/2 HTTP/1.1 Host: the-website.com HTTP/1.1 204 No Content Id Name 1 Alice 2 Bob 3 Claire Users
  • 17. A server with information about users.  The PATCH method is used to update parts of a resource. PATCH /users/1 HTTP/1.1 Host: the-website.com Content-Type: application/xml Content-Length: 37 <user> <name>Amanda</human> </user> HTTP/1.1 204 No Content The PATCH method is only a proposed standard. Id Name 1 Alice 2 Bob 3 Claire Users
  • 18. A server with information about users.  What if something goes wrong?  Use the HTTP status codes to indicate success/failure. GET /users/999 HTTP/1.1 Host: the-website.com Accept: application/json HTTP/1.1 404 Not Found • Read more about the different status codes at: • http://www.restapitutorial.com/httpstatuscodes.html • Optionally include error messages in the response body. Id Name 1 Alice 2 Bob 3 Claire Users
  • 19. How should you think?  Make it as easy as possible to use by other programmers. Facebook:  Always return 200 OK.  GET /v2.7/{user-id}  GET /v2.7/{post-id}  GET /v2.7/{user-id}/friends  GET /v2.7/{object-id}/likes
  • 20. How should you think?  Make it as easy as possible to use by other programmers. Twitter:  Only use GET and POST.  GET /1.1/users/show.json?user_id=2244994945  POST /1.1/favorites/destroy.json?id=243138128959913986