SlideShare una empresa de Scribd logo
1 de 22
S U R I N D E R K U M A R M E H R A
7 T H S E P T , 2 0 1 5
For "REST“, keep watching. For others,
Open Rest.
RESTFul Web Services
Outline
 Introduction
 REST and HTTP
 Resource Types
 Base URL
 HTTP Methods
 Method Idempotence
 HATEOAS
 Richardson Maturity
Model
 Path and Query Params
 Pagination and Filtering
 Sub Resources
 Exceptions
 Content Negotiation
Introduction
 REpresentational State Transfer (REST)
 An architectural Style
 Coordinated set of constraints to
distributed hypermedia system components design
 REST+Web Services = RESTFul Web Services
 Web sites use HTML with format and styling
 Meant for human consumption
 REST use XML/JSON without styling- bare bone
data
 Meant of Developers to use and style accordingly
 Has specific URL for each operation
 Just like static web page web sites
Introduction Contd…
Characteristics of Web Services
 Communication always happens over Web/HTTP
 Protocols:
 SOAP Web services: SOAP format
 REST: none… Can be XML/JSON/TEXT as long as client
server understand each other
 Data Exchange:
 SOAP: Always POST
 REST: Different methods for different purpose
 Service definition:
 SOAP: WSDL
 REST: None
Why No Rules in REST
 SOAP WS follow SOAP Web service Specification
 If SOAP WS does no follow even one rule , its not SOAP WS
 Committee maintains the rules
 REST is a concept introduced by Roy Fielding
 There is no committee to make rules
Why REST
• Used when lot of tiny data is needed
• Easy to build- No toolkit required
• Light weight- NO xml markup
• Independence- no strict rules like SOAP
• For bulk operations like detailed purchase order may not be
possible with REST
Little bit about HTTP
 HTTP: Hyper Text Transfer Protocol
 HTTP is a way to transfer/exchange hypertext
 Hypertext is a structured text which contains logical links to
other text.
 Logical links are called hyperlinks
 A common way to write hyper text is HTML
 HTML: Hyper Text Markup Language
HTTP Status Codes
 1XX - Informational
 2XX – Success
 3XX – Redirectional
 4XX – Client Error
 5XX – Server Error
HTTP & REST
 Address Resource Locations:
 Web sites use action based URI’s
 weatherapp.com/weatherLookup.do?zipcode=1234
 REST uses resource based URI’s
 weatherapp.com/zipcode/1234
 weatherapp.com/cities/Bengaluru
 Methods: GET, PUT , POST, DELETE
 Metadata:
 Status Codes: Defines status of response received
 Message Headers: type of data sent/received
Roy Fielding was one of the principal authors of HTTP Specification
Resource Types
 Instance Resources
 http://localhost:8081/messenger/webapi/messages/1
 Collection Resources
 http://localhost:8081/messenger/webapi/messages/
HTTP Methods
 GET
 PUT
 POST
 DELETE
 Few others
Method Idempotence
Idempotence :
Resource state on server is same before and after the
operation with same data
 PUT and DELETE are idempotent
 GET is Safe and therefore Idempotent
 POST is not idempotent
• Why ?
HATEOAS
 Hypermedia
 As
 The
 Engine
 Of
 Application
 State
 In short provides dynamic current Application state
Richardson Maturity Model
 Level 0: Swamp Of POX(Plain Old XML)
 Uses one entry point and one method-SOAP
 Level 1: Resource URI’s
 Individual URI’s for each resource and one method
 Level 2: HTTP Methods
 Uses the right HTTP method and status codes
 Level 3: HATEOAS
 Response have links that client can use further
Annotations
 @Path
 @Produces
 @Consumes
 @PathParam
 @Context
 @HeaderParam
Pagination & Filtering
 @QueryParam: Apply to request as a whole
 @MatrixParam: Apply to path element
 @BeanParam: Useful when lot of params are
needed.
Collection Resource supports query params:
 Offset
 Limit
…/messages?offset=50&limit=25
Sub Resources
@Path(“/parentId/subresourcemapping”)
getSubResourceAPI(){}
• The path of parent resource becomes the Base URI for Sub
Resource
Status Codes and Location Headers
 Return proper Status Code in Response
 201 instead of 200 when POST is successful
 Send Location Headers in Response
Content Negotiation
 Accept Header: What do I accept
 Content- Type: What am I sending
Exceptions Handling
 Custom Exception Mapper
 Generics Exception Mapper
 WebApplicationException
 ClientErrorException- for error code 4XX
 RedirectionException – for error code 3XX
 ServerErrorException – for error code 5XX
 Specific classes for each of above categories
Thank You !

Más contenido relacionado

La actualidad más candente

introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)FabMinds
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web servicesnbuddharaju
 
Introduction to Web Services
Introduction to Web ServicesIntroduction to Web Services
Introduction to Web ServicesJeffrey Anderson
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraintInviqa
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServicesPrateek Tandon
 
Impact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilityImpact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilitySanchit Gera
 
Intro to Web Services - 2015 STC Summit talk
Intro to Web Services - 2015 STC Summit talkIntro to Web Services - 2015 STC Summit talk
Intro to Web Services - 2015 STC Summit talkEd Marshall
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web ServicesSalesforce Developers
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTelliando dias
 
Abhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techAbhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techabhishek srivastav
 

La actualidad más candente (20)

REST API
REST APIREST API
REST API
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
introduction for web connectivity (IoT)
introduction for web connectivity (IoT)introduction for web connectivity (IoT)
introduction for web connectivity (IoT)
 
Design patternsforiot
Design patternsforiotDesign patternsforiot
Design patternsforiot
 
REST API Design
REST API DesignREST API Design
REST API Design
 
Rest http basics
Rest http basicsRest http basics
Rest http basics
 
Overview of RESTful web services
Overview of RESTful web servicesOverview of RESTful web services
Overview of RESTful web services
 
Introduction to Web Services
Introduction to Web ServicesIntroduction to Web Services
Introduction to Web Services
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
Odata
OdataOdata
Odata
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
Impact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and ScalabilityImpact of Restful Web Architecture on Performance and Scalability
Impact of Restful Web Architecture on Performance and Scalability
 
Intro to Web Services - 2015 STC Summit talk
Intro to Web Services - 2015 STC Summit talkIntro to Web Services - 2015 STC Summit talk
Intro to Web Services - 2015 STC Summit talk
 
Best Practices for RESTful Web Services
Best Practices for RESTful Web ServicesBest Practices for RESTful Web Services
Best Practices for RESTful Web Services
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Abhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_techAbhishek srivastava ppt_web_tech
Abhishek srivastava ppt_web_tech
 
Rest web services
Rest web servicesRest web services
Rest web services
 

Similar a Restful web services

Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with javaVinay Gopinath
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIsamesar0
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response StructureBhagyashreeGajera1
 
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianAPI Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianVahid Rahimian
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASGuy K. Kloss
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
RESTful web services using java and spring
RESTful web services using java and springRESTful web services using java and spring
RESTful web services using java and springMuhammad Junaid Ansari
 
Research Topics in Machine Hypermedia
Research Topics in Machine HypermediaResearch Topics in Machine Hypermedia
Research Topics in Machine HypermediaMichael Koster
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
Rest Best Practices
Rest Best  PracticesRest Best  Practices
Rest Best PracticesDhiraj Rai
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web ServicesPaul Boocock
 

Similar a Restful web services (20)

Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
HTTP Request and Response Structure
HTTP Request and Response StructureHTTP Request and Response Structure
HTTP Request and Response Structure
 
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianAPI Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 
A Look at OData
A Look at ODataA Look at OData
A Look at OData
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOASRepresentational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Best Practices in Api Design
Best Practices in Api DesignBest Practices in Api Design
Best Practices in Api Design
 
RESTful web services using java and spring
RESTful web services using java and springRESTful web services using java and spring
RESTful web services using java and spring
 
Research Topics in Machine Hypermedia
Research Topics in Machine HypermediaResearch Topics in Machine Hypermedia
Research Topics in Machine Hypermedia
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
Rest Best Practices
Rest Best  PracticesRest Best  Practices
Rest Best Practices
 
Writing RESTful Web Services
Writing RESTful Web ServicesWriting RESTful Web Services
Writing RESTful Web Services
 

Último

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 

Último (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 

Restful web services

  • 1. S U R I N D E R K U M A R M E H R A 7 T H S E P T , 2 0 1 5 For "REST“, keep watching. For others, Open Rest. RESTFul Web Services
  • 2. Outline  Introduction  REST and HTTP  Resource Types  Base URL  HTTP Methods  Method Idempotence  HATEOAS  Richardson Maturity Model  Path and Query Params  Pagination and Filtering  Sub Resources  Exceptions  Content Negotiation
  • 3. Introduction  REpresentational State Transfer (REST)  An architectural Style  Coordinated set of constraints to distributed hypermedia system components design  REST+Web Services = RESTFul Web Services  Web sites use HTML with format and styling  Meant for human consumption  REST use XML/JSON without styling- bare bone data  Meant of Developers to use and style accordingly  Has specific URL for each operation  Just like static web page web sites
  • 5. Characteristics of Web Services  Communication always happens over Web/HTTP  Protocols:  SOAP Web services: SOAP format  REST: none… Can be XML/JSON/TEXT as long as client server understand each other  Data Exchange:  SOAP: Always POST  REST: Different methods for different purpose  Service definition:  SOAP: WSDL  REST: None
  • 6. Why No Rules in REST  SOAP WS follow SOAP Web service Specification  If SOAP WS does no follow even one rule , its not SOAP WS  Committee maintains the rules  REST is a concept introduced by Roy Fielding  There is no committee to make rules
  • 7. Why REST • Used when lot of tiny data is needed • Easy to build- No toolkit required • Light weight- NO xml markup • Independence- no strict rules like SOAP • For bulk operations like detailed purchase order may not be possible with REST
  • 8. Little bit about HTTP  HTTP: Hyper Text Transfer Protocol  HTTP is a way to transfer/exchange hypertext  Hypertext is a structured text which contains logical links to other text.  Logical links are called hyperlinks  A common way to write hyper text is HTML  HTML: Hyper Text Markup Language
  • 9. HTTP Status Codes  1XX - Informational  2XX – Success  3XX – Redirectional  4XX – Client Error  5XX – Server Error
  • 10. HTTP & REST  Address Resource Locations:  Web sites use action based URI’s  weatherapp.com/weatherLookup.do?zipcode=1234  REST uses resource based URI’s  weatherapp.com/zipcode/1234  weatherapp.com/cities/Bengaluru  Methods: GET, PUT , POST, DELETE  Metadata:  Status Codes: Defines status of response received  Message Headers: type of data sent/received Roy Fielding was one of the principal authors of HTTP Specification
  • 11. Resource Types  Instance Resources  http://localhost:8081/messenger/webapi/messages/1  Collection Resources  http://localhost:8081/messenger/webapi/messages/
  • 12. HTTP Methods  GET  PUT  POST  DELETE  Few others
  • 13. Method Idempotence Idempotence : Resource state on server is same before and after the operation with same data  PUT and DELETE are idempotent  GET is Safe and therefore Idempotent  POST is not idempotent • Why ?
  • 14. HATEOAS  Hypermedia  As  The  Engine  Of  Application  State  In short provides dynamic current Application state
  • 15. Richardson Maturity Model  Level 0: Swamp Of POX(Plain Old XML)  Uses one entry point and one method-SOAP  Level 1: Resource URI’s  Individual URI’s for each resource and one method  Level 2: HTTP Methods  Uses the right HTTP method and status codes  Level 3: HATEOAS  Response have links that client can use further
  • 16. Annotations  @Path  @Produces  @Consumes  @PathParam  @Context  @HeaderParam
  • 17. Pagination & Filtering  @QueryParam: Apply to request as a whole  @MatrixParam: Apply to path element  @BeanParam: Useful when lot of params are needed. Collection Resource supports query params:  Offset  Limit …/messages?offset=50&limit=25
  • 18. Sub Resources @Path(“/parentId/subresourcemapping”) getSubResourceAPI(){} • The path of parent resource becomes the Base URI for Sub Resource
  • 19. Status Codes and Location Headers  Return proper Status Code in Response  201 instead of 200 when POST is successful  Send Location Headers in Response
  • 20. Content Negotiation  Accept Header: What do I accept  Content- Type: What am I sending
  • 21. Exceptions Handling  Custom Exception Mapper  Generics Exception Mapper  WebApplicationException  ClientErrorException- for error code 4XX  RedirectionException – for error code 3XX  ServerErrorException – for error code 5XX  Specific classes for each of above categories