SlideShare a Scribd company logo
1 of 14
STANDARDS OF REST API Mayur Chourasiya
REST
APIS
Web services are purpose-built web servers that support the needs of a site or
any other application. Client programs use application programming interfaces
(APIs) to communicate with web services. Generally speaking, an API exposes a
set of data and functions to facilitate interactions between computer programs
and allow them to exchange information. As depicted in Figure, a Web API is
the face of a web service, directly listening and responding to client requests.
The REST architectural style is commonly applied to the design of APIs for modern
web services. A Web API conforming to the REST architectural style is a REST API.
Having a REST API makes a web service “RESTful.” A REST API consists of an
assembly of interlinked resources. This set of resources is known as the REST
API’s resource model.
Application Programming Interface (API)
Exposes a set of data and functions to facilitate interactions between computer
programs.
HyperText Mark-up Language (HTML)
Created by Tim Berners-Lee to represent the state of a web resource’s information and
relationships.
HyperText Transfer Protocol (HTTP)
Originally developed by Tim Berners-Lee, this is a message-based language that
computers could use to communicate over the Internet.
Hypertext Transfer Protocol version 1.1 (HTTP/1.1)
Roy Fielding, Tim Berners-Lee, and others contributed to the standardization of this
most recent version of the communication protocol.
Resource
Any Web-based concept that can be referenced by a unique identifier and manipulated
via the uniform interface.
Uniform Resource Identifier (URI)
A syntax invented by Tim Berners-Lee to assign each web resource a unique ID.
Web Resource Modeling Language (WRML)
A conceptual framework whose ideas can be leveraged to design and implement
uniform REST APIs.
Web component (component)
A client, network-based intermediary, or server that complies with REST’s uniform
interface.
Web server (server)
A computer program that follows REST’s uniform interface constraints in order to accept
and transfer resource state representations to clients.
Web service
A web server programmed with specific, often reusable, logic.
IDENTIFIER DESIGN WITH URIS
 REST APIs use Uniform Resource Identifiers (URIs) to address resources.
URI Format : scheme "://" authority "/" path [ “?” query ] [ "#" fragment ]
RULES for Format of URI
 FORWARD SLASH SEPARATOR (/) MUST BE USED TO INDICATE A HIERARCHICAL RELATIONSHIP
http://api.canvas.restapi.org/shapes/polygons/quadrilaterals/squares
 A TRAILING FORWARD SLASH (/) SHOULD NOT BE INCLUDED IN URI
http://api.canvas.restapi.org/shapes/
 HYPHENS (-) SHOULD BE USED TO IMPROVE THE READABILITY OF URIS
http://api.example.restapi.org/blogs/mark-masse/entries/this-is-my-first-post
 UNDERSCORES (_) SHOULD NOT BE USED IN URIS
 LOWERCASE LETTERS SHOULD BE PREFERRED IN URI PATHS
http://api.example.restapi.org/my-folder/my-doc
 FILE EXTENSIONS SHOULD NOT BE INCLUDED IN URIS
http://api.college.restapi.org/students/3248234/transcripts/2005/fall.json -
incorrect
http://api.college.restapi.org/students/3248234/transcripts/2005/fall -
correct
URI PATH DESIGN RULES
 WRML diagram of a URI’s associated resource model
 A SINGULAR NOUN SHOULD BE USED FOR DOCUMENT NAMES
For example, the URI for a single player document would have the singular form:
http://api.soccer.restapi.org/leagues/seattle/teams/trebuchet/players/ronaldo
 A PLURAL NOUN SHOULD BE USED FOR COLLECTION NAMES
 A PLURAL NOUN SHOULD BE USED FOR STORE NAMES
http://api.music.restapi.org/artists/mikemassedotcom/playlists
 A VERB OR VERB PHRASE SHOULD BE USED FOR CONTROLLER NAMES
Like a computer program’s function, a URI identifying a controller resource should
be named to indicate its action. For example:
http://api.college.restapi.org/students/morgan/register
http://api.example.restapi.org/lists/4324/dedupe
http://api.ognom.restapi.org/dbs/reindex
http://api.build.restapi.org/qa/nightly/runTestSuite
 VARIABLE PATH SEGMENTS MAY BE SUBSTITUTED WITH IDENTITY-
BASED VALUES
http://api.soccer.restapi.org/leagues/{leagueId}/teams/{teamId}/players/{playerId}
 CRUD FUNCTION NAMES SHOULD NOT BE USED IN URIS
DELETE /users/1234 - Preferred
GET /deleteUser?id=1234
GET /deleteUser/1234 Not Preferred
DELETE /deleteUser/1234
POST /users/1234/delete
INTERACTION DESIGN WITH HTTP
Each HTTP method has specific, well-defined semantics within the
context of a REST API’s resource model. The purpose of GET is to
retrieve a representation of a resource’s state. HEAD is used to
retrieve the metadata associated with the resource’s state. PUT
should be used to add a new resource to a store or update a
resource. DELETE removes a resource from its parent. POST should be
used to create a new resource within a collection and execute
controllers.
RULES :
 GET AND POST MUST NOT BE USED TO TUNNEL OTHER REQUEST METHODS
Tunneling refers to any abuse of HTTP that masks or misrepresents a message’s intent and undermines the
protocol’s transparency. A REST API must not compromise its design by misusing HTTP’s request methods in
an effort to accommodate clients with limited HTTP vocabulary. Always make proper use of the HTTP
methods as specified by the rules in this section.
 GET MUST BE USED TO RETRIEVE A REPRESENTATION OF A RESOURCE
A REST API client uses the GET method in a request message to retrieve the state of a resource, in some
representational form. A client’s GET request message may contain headers but no body.
The architecture of the Web relies heavily on the nature of the GET method. Clients count on being able to repeat
GET requests without causing side effects. Caches depend on the ability to serve cached representations without
contacting the origin server.
In the example below, we can see how a client developer might use curl from a command shell to GET a
representation of a “greeting” resource’s current state:
C:api> curl -v http://api.example.restapi.org/greeting
GET /greeting HTTP/1.1
User-Agent: curl/7.20.1
Host: api.example.restapi.org
Accept: */*
HTTP/1.1 200 OK
Date: Sat, 20 Aug 2011 16:02:40 GMT
Server: Apache
Expires: Sat, 20 Aug 2011 16:03:40 GMT
Cache-Control: max-age=60, must-revalidate
ETag: text/html:hello world
Content-Length: 130
Last-Modified: Sat, 20 Aug 2011 16:02:17 GMT
Vary: Accept-Encoding
Content-Type: text/html
<!doctype html><head><meta charset="utf-8"><title>Greeting</title></head> 6
<body><div id="greeting">Hello World!</div></body></html>
 HEAD SHOULD BE USED TO RETRIEVE RESPONSE HEADERS
Clients use HEAD to retrieve the headers without a body. In other words, HEAD returns the same response as
GET, except that the API returns an empty body. Clients can use this method to check whether a resource
exists or to read its metadata.
$ curl --head http://api.example.restapi.org/greeting
HTTP/1.1 200 OK 1
Date: Sat, 20 Aug 2011 16:02:40 GMT 2
Server: Apache
Expires: Sat, 20 Aug 2011 16:03:40 GMT
Cache-Control: max-age=60, must-revalidate
ETag: text/html:hello world
Content-Length: 130
Last-Modified: Sat, 20 Aug 2011 16:02:17 GMT
Vary: Accept-Encoding
Content-Type: text/html
Like GET, a HEAD request message may contain headers but no body.
 PUT MUST BE USED TO BOTH INSERT AND UPDATE A STORED
RESOURCE
PUT must be used to add a new resource to a store, with a URI specified by the client. PUT must also be
used to update or replace an already stored resource.
 PUT MUST BE USED TO UPDATE MUTABLE RESOURCES
Clients must use the PUT request method to make changes to resources. The PUT request message may
include a body that reflects the desired changes.
 POST MUST BE USED TO CREATE A NEW RESOURCE IN A
COLLECTION
Clients use POST when attempting to create a new resource within a collection. The POST request’s body
contains the suggested state representation of the new resource to be added to the server-owned
collection.
The example below demonstrates how a client uses POST to request a new addition to a collection:
Example : POST /leagues/seattle/teams/trebuchet/players
 POST MUST BE USED TO EXECUTE CONTROLLERS
Clients use the POST method to invoke the function-oriented controller resources. A POST request message
may include both headers and a body as inputs to a controller resource’s function.
POST method should not be used to get, store, or delete resources—HTTP already provides specific
methods for each of those functions.
The example below demonstrates how a controller can be executed using the POST request method:
Example : POST /alerts/245743/resend
 DELETE MUST BE USED TO REMOVE A RESOURCE FROM ITS PARENT
A client uses DELETE to request that a resource be completely removed from its parent, which is often a
collection or store. Once a DELETE request has been processed for a given resource, the resource can no
longer be found by clients. Therefore, any future attempt to retrieve the resource’s state representation,
using either GET or HEAD, must result in a 404 (“Not Found”) status returned by the API.
The example below shows how a client might remove a document from a store:
DELETE /accounts/4ef2d5d0-cb7e-11e0-9572-0800200c9a66/buckets/objects/4321
 OPTIONS SHOULD BE USED TO RETRIEVE METADATA THAT
DESCRIBES A RESOURCE’S AVAILABLE INTERACTIONS
Clients may use the OPTIONS request method to retrieve resource metadata that includes an Allow header
value. For example:The example below demonstrates how a client uses POST to request a new addition to a
collection:
Allow: GET, PUT, DELETE
RESPONSE STATUS CODES
Category Description
1xx: Informational Communicates transfer protocol-level information.
2xx: Success Indicates that the client’s request was accepted successfully.
3xx: Redirection
Indicates that the client must take some additional action in order to complete their
request.
4xx: Client Error This category of error status codes points the finger at clients.
5xx: Server Error The server takes responsibility for these error status codes.
Term Description
DELETE HTTP request method used to remove its parent.
GET HTTP request method used to retrieve a representation of a resource’s state.
HEAD HTTP request method used to retrieve the metadata associated with the resource’s state.
OPTIONS HTTP request method used to retrieve metadata that describes a resource’s available interactions.
POST HTTP request method used to create a new resource within a collection or execute a controller.
PUT HTTP request method used to insert a new resource into a store or update a mutable resource.
Request-Line RFC 2616 defines its syntax as Method SP Request-URI SP HTTP-Version CRLF
Request method Indicates the desired action to be performed on the request message’s identified resource.
Response status code A three-digit numeric value that is communicated by a server to indicate the result of a client’s request.
Status-Line RFC 2616 defines its syntax as: HTTP-Version SP Status-Code SP Reason-Phrase CRLF
Tunneling
An abuse of HTTP that masks or misrepresents a message’s intent and undermines the protocol’s
transparency.

More Related Content

What's hot

Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
Liam Cleary [MVP]
 

What's hot (20)

Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
Are you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint AppsAre you getting Sleepy. REST in SharePoint Apps
Are you getting Sleepy. REST in SharePoint Apps
 
RESTful API - Best Practices
RESTful API - Best PracticesRESTful API - Best Practices
RESTful API - Best Practices
 
REST Architecture with use case and example
REST Architecture with use case and exampleREST Architecture with use case and example
REST Architecture with use case and example
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
 
SPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx WebpartSPFx Webinar Loading SharePoint data in a SPFx Webpart
SPFx Webinar Loading SharePoint data in a SPFx Webpart
 
Spring HATEOAS
Spring HATEOASSpring HATEOAS
Spring HATEOAS
 
Api apex rest
Api apex restApi apex rest
Api apex rest
 
Spring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing PeopleSpring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing People
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)Annotation Tools (OA European Roll Out)
Annotation Tools (OA European Roll Out)
 
Representational State Transfer (REST)
Representational State Transfer (REST)Representational State Transfer (REST)
Representational State Transfer (REST)
 
REST API
REST APIREST API
REST API
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / concepts
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
REST - Representational State Transfer
REST - Representational State TransferREST - Representational State Transfer
REST - Representational State Transfer
 

Similar to Standards of rest api

How to design a good rest api tools, techniques and best practices.
How to design a good rest api  tools, techniques and best practices.How to design a good rest api  tools, techniques and best practices.
How to design a good rest api tools, techniques and best practices.
Nuwan Dias
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
vikram singh
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh
 

Similar to Standards of rest api (20)

WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Api design and development
Api design and developmentApi design and development
Api design and development
 
RESTful Web Development with CakePHP
RESTful Web Development with CakePHPRESTful Web Development with CakePHP
RESTful Web Development with CakePHP
 
C# REST API
C# REST APIC# REST API
C# REST API
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Implementation web api
Implementation web apiImplementation web api
Implementation web api
 
Richarson maturity model (HATEOAS)
Richarson maturity model (HATEOAS)Richarson maturity model (HATEOAS)
Richarson maturity model (HATEOAS)
 
Rest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbookRest api best practices – comprehensive handbook
Rest api best practices – comprehensive handbook
 
How to design a good rest api tools, techniques and best practices.
How to design a good rest api  tools, techniques and best practices.How to design a good rest api  tools, techniques and best practices.
How to design a good rest api tools, techniques and best practices.
 
API Basics
API BasicsAPI Basics
API Basics
 
Asp.net web api
Asp.net web apiAsp.net web api
Asp.net web api
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 
REST library.pptx
REST library.pptxREST library.pptx
REST library.pptx
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 

Standards of rest api

  • 1. STANDARDS OF REST API Mayur Chourasiya
  • 2. REST APIS Web services are purpose-built web servers that support the needs of a site or any other application. Client programs use application programming interfaces (APIs) to communicate with web services. Generally speaking, an API exposes a set of data and functions to facilitate interactions between computer programs and allow them to exchange information. As depicted in Figure, a Web API is the face of a web service, directly listening and responding to client requests. The REST architectural style is commonly applied to the design of APIs for modern web services. A Web API conforming to the REST architectural style is a REST API. Having a REST API makes a web service “RESTful.” A REST API consists of an assembly of interlinked resources. This set of resources is known as the REST API’s resource model.
  • 3. Application Programming Interface (API) Exposes a set of data and functions to facilitate interactions between computer programs. HyperText Mark-up Language (HTML) Created by Tim Berners-Lee to represent the state of a web resource’s information and relationships. HyperText Transfer Protocol (HTTP) Originally developed by Tim Berners-Lee, this is a message-based language that computers could use to communicate over the Internet. Hypertext Transfer Protocol version 1.1 (HTTP/1.1) Roy Fielding, Tim Berners-Lee, and others contributed to the standardization of this most recent version of the communication protocol. Resource Any Web-based concept that can be referenced by a unique identifier and manipulated via the uniform interface.
  • 4. Uniform Resource Identifier (URI) A syntax invented by Tim Berners-Lee to assign each web resource a unique ID. Web Resource Modeling Language (WRML) A conceptual framework whose ideas can be leveraged to design and implement uniform REST APIs. Web component (component) A client, network-based intermediary, or server that complies with REST’s uniform interface. Web server (server) A computer program that follows REST’s uniform interface constraints in order to accept and transfer resource state representations to clients. Web service A web server programmed with specific, often reusable, logic.
  • 5. IDENTIFIER DESIGN WITH URIS  REST APIs use Uniform Resource Identifiers (URIs) to address resources. URI Format : scheme "://" authority "/" path [ “?” query ] [ "#" fragment ] RULES for Format of URI  FORWARD SLASH SEPARATOR (/) MUST BE USED TO INDICATE A HIERARCHICAL RELATIONSHIP http://api.canvas.restapi.org/shapes/polygons/quadrilaterals/squares  A TRAILING FORWARD SLASH (/) SHOULD NOT BE INCLUDED IN URI http://api.canvas.restapi.org/shapes/  HYPHENS (-) SHOULD BE USED TO IMPROVE THE READABILITY OF URIS http://api.example.restapi.org/blogs/mark-masse/entries/this-is-my-first-post  UNDERSCORES (_) SHOULD NOT BE USED IN URIS  LOWERCASE LETTERS SHOULD BE PREFERRED IN URI PATHS http://api.example.restapi.org/my-folder/my-doc  FILE EXTENSIONS SHOULD NOT BE INCLUDED IN URIS http://api.college.restapi.org/students/3248234/transcripts/2005/fall.json - incorrect http://api.college.restapi.org/students/3248234/transcripts/2005/fall - correct
  • 6. URI PATH DESIGN RULES  WRML diagram of a URI’s associated resource model  A SINGULAR NOUN SHOULD BE USED FOR DOCUMENT NAMES For example, the URI for a single player document would have the singular form: http://api.soccer.restapi.org/leagues/seattle/teams/trebuchet/players/ronaldo  A PLURAL NOUN SHOULD BE USED FOR COLLECTION NAMES  A PLURAL NOUN SHOULD BE USED FOR STORE NAMES http://api.music.restapi.org/artists/mikemassedotcom/playlists
  • 7.  A VERB OR VERB PHRASE SHOULD BE USED FOR CONTROLLER NAMES Like a computer program’s function, a URI identifying a controller resource should be named to indicate its action. For example: http://api.college.restapi.org/students/morgan/register http://api.example.restapi.org/lists/4324/dedupe http://api.ognom.restapi.org/dbs/reindex http://api.build.restapi.org/qa/nightly/runTestSuite  VARIABLE PATH SEGMENTS MAY BE SUBSTITUTED WITH IDENTITY- BASED VALUES http://api.soccer.restapi.org/leagues/{leagueId}/teams/{teamId}/players/{playerId}  CRUD FUNCTION NAMES SHOULD NOT BE USED IN URIS DELETE /users/1234 - Preferred GET /deleteUser?id=1234 GET /deleteUser/1234 Not Preferred DELETE /deleteUser/1234 POST /users/1234/delete
  • 8. INTERACTION DESIGN WITH HTTP Each HTTP method has specific, well-defined semantics within the context of a REST API’s resource model. The purpose of GET is to retrieve a representation of a resource’s state. HEAD is used to retrieve the metadata associated with the resource’s state. PUT should be used to add a new resource to a store or update a resource. DELETE removes a resource from its parent. POST should be used to create a new resource within a collection and execute controllers. RULES :  GET AND POST MUST NOT BE USED TO TUNNEL OTHER REQUEST METHODS Tunneling refers to any abuse of HTTP that masks or misrepresents a message’s intent and undermines the protocol’s transparency. A REST API must not compromise its design by misusing HTTP’s request methods in an effort to accommodate clients with limited HTTP vocabulary. Always make proper use of the HTTP methods as specified by the rules in this section.  GET MUST BE USED TO RETRIEVE A REPRESENTATION OF A RESOURCE A REST API client uses the GET method in a request message to retrieve the state of a resource, in some representational form. A client’s GET request message may contain headers but no body.
  • 9. The architecture of the Web relies heavily on the nature of the GET method. Clients count on being able to repeat GET requests without causing side effects. Caches depend on the ability to serve cached representations without contacting the origin server. In the example below, we can see how a client developer might use curl from a command shell to GET a representation of a “greeting” resource’s current state: C:api> curl -v http://api.example.restapi.org/greeting GET /greeting HTTP/1.1 User-Agent: curl/7.20.1 Host: api.example.restapi.org Accept: */* HTTP/1.1 200 OK Date: Sat, 20 Aug 2011 16:02:40 GMT Server: Apache Expires: Sat, 20 Aug 2011 16:03:40 GMT Cache-Control: max-age=60, must-revalidate ETag: text/html:hello world Content-Length: 130 Last-Modified: Sat, 20 Aug 2011 16:02:17 GMT Vary: Accept-Encoding Content-Type: text/html <!doctype html><head><meta charset="utf-8"><title>Greeting</title></head> 6 <body><div id="greeting">Hello World!</div></body></html>
  • 10.  HEAD SHOULD BE USED TO RETRIEVE RESPONSE HEADERS Clients use HEAD to retrieve the headers without a body. In other words, HEAD returns the same response as GET, except that the API returns an empty body. Clients can use this method to check whether a resource exists or to read its metadata. $ curl --head http://api.example.restapi.org/greeting HTTP/1.1 200 OK 1 Date: Sat, 20 Aug 2011 16:02:40 GMT 2 Server: Apache Expires: Sat, 20 Aug 2011 16:03:40 GMT Cache-Control: max-age=60, must-revalidate ETag: text/html:hello world Content-Length: 130 Last-Modified: Sat, 20 Aug 2011 16:02:17 GMT Vary: Accept-Encoding Content-Type: text/html Like GET, a HEAD request message may contain headers but no body.
  • 11.  PUT MUST BE USED TO BOTH INSERT AND UPDATE A STORED RESOURCE PUT must be used to add a new resource to a store, with a URI specified by the client. PUT must also be used to update or replace an already stored resource.  PUT MUST BE USED TO UPDATE MUTABLE RESOURCES Clients must use the PUT request method to make changes to resources. The PUT request message may include a body that reflects the desired changes.  POST MUST BE USED TO CREATE A NEW RESOURCE IN A COLLECTION Clients use POST when attempting to create a new resource within a collection. The POST request’s body contains the suggested state representation of the new resource to be added to the server-owned collection. The example below demonstrates how a client uses POST to request a new addition to a collection: Example : POST /leagues/seattle/teams/trebuchet/players  POST MUST BE USED TO EXECUTE CONTROLLERS Clients use the POST method to invoke the function-oriented controller resources. A POST request message may include both headers and a body as inputs to a controller resource’s function. POST method should not be used to get, store, or delete resources—HTTP already provides specific methods for each of those functions. The example below demonstrates how a controller can be executed using the POST request method: Example : POST /alerts/245743/resend
  • 12.  DELETE MUST BE USED TO REMOVE A RESOURCE FROM ITS PARENT A client uses DELETE to request that a resource be completely removed from its parent, which is often a collection or store. Once a DELETE request has been processed for a given resource, the resource can no longer be found by clients. Therefore, any future attempt to retrieve the resource’s state representation, using either GET or HEAD, must result in a 404 (“Not Found”) status returned by the API. The example below shows how a client might remove a document from a store: DELETE /accounts/4ef2d5d0-cb7e-11e0-9572-0800200c9a66/buckets/objects/4321  OPTIONS SHOULD BE USED TO RETRIEVE METADATA THAT DESCRIBES A RESOURCE’S AVAILABLE INTERACTIONS Clients may use the OPTIONS request method to retrieve resource metadata that includes an Allow header value. For example:The example below demonstrates how a client uses POST to request a new addition to a collection: Allow: GET, PUT, DELETE
  • 13. RESPONSE STATUS CODES Category Description 1xx: Informational Communicates transfer protocol-level information. 2xx: Success Indicates that the client’s request was accepted successfully. 3xx: Redirection Indicates that the client must take some additional action in order to complete their request. 4xx: Client Error This category of error status codes points the finger at clients. 5xx: Server Error The server takes responsibility for these error status codes.
  • 14. Term Description DELETE HTTP request method used to remove its parent. GET HTTP request method used to retrieve a representation of a resource’s state. HEAD HTTP request method used to retrieve the metadata associated with the resource’s state. OPTIONS HTTP request method used to retrieve metadata that describes a resource’s available interactions. POST HTTP request method used to create a new resource within a collection or execute a controller. PUT HTTP request method used to insert a new resource into a store or update a mutable resource. Request-Line RFC 2616 defines its syntax as Method SP Request-URI SP HTTP-Version CRLF Request method Indicates the desired action to be performed on the request message’s identified resource. Response status code A three-digit numeric value that is communicated by a server to indicate the result of a client’s request. Status-Line RFC 2616 defines its syntax as: HTTP-Version SP Status-Code SP Reason-Phrase CRLF Tunneling An abuse of HTTP that masks or misrepresents a message’s intent and undermines the protocol’s transparency.