SlideShare une entreprise Scribd logo
1  sur  63
A Conversation About REST
          Jeremy Brown
        notmessenger.com
What is an API?
What is an API?
From Wikipedia:

An application programming interface (API)
is a particular set of rules and specifications
that a software program can follow to access
and make use of the services and resources
provided by another software program that
implements the API.
What is an API?
Wikipedia continues:

It serves as an interface between different
software programs and facilitates their
interaction, similar to the way the user
interface facilitates interaction between
humans and computers.
What is an API?
Our understanding:

Set of rules and specifications to facilitate
the interaction between different software
programs.
Examples
mkdir

format
Types of APIs
XML-RPC (1998)

SOAP (1998, 2003)

JSON-RPC (2005)

REST (2000)
XML-RPC
xmlrpc.com

It’s remote procedure calling using HTTP as
the transport and XML as the encoding.
XML-RPC is designed to be as simple as
possible, while allowing complex data
structures to be transmitted, processed and
returned.
XML-RPC
xmlrpc.com also says:
We wanted a clean, extensible format that’s very
simple. It should be possible for an HTML coder to
be able to look at a file containing an XML-RPC
call, understand what it’s doing, and be able to
modify it and have it work on the first or second
try... We also wanted it to be an easy protocol
that could quickly be adapted to run in other
environments or on other operating systems.
XML-RPC
Sample Request:
<?xml version="1.0"?>
<methodCall>
  <methodName>getStateName</methodName>
  <params>
    <param>
        <value><int>40</int></value>
    </param>
  </params>
</methodCall>
XML-RPC
Sample Request:
<?xml version="1.0"?>
<methodCall>
  <methodName>getStateName</methodName>
  <params>
    <param>
        <value><int>40</int></value>
    </param>
  </params>
</methodCall>



Sample Response:
<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
        <value><string>South Dakota</string></value>
    </param>
  </params>
</methodResponse>
SOAP
SOAP spec:
SOAP is a lightweight protocol for exchange of
information in a decentralized, distributed
environment. It is an XML based protocol that
consists of three parts: an envelope that defines a
framework for describing what is in a message and
how to process it, a set of encoding rules for
expressing instances of application-defined datatypes,
and a convention for representing remote procedure
calls and responses.
SOAP
Sample Request:
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 299

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Header>
  </soap:Header>
  <soap:Body>
    <m:GetStockPrice xmlns:m="http://www.example.org/stock">
      <m:StockName>IBM</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>
JSON-RPC
Wikipedia says:

JSON-RPC is a remote procedure call
protocol encoded in JSON. It is a very simple
protocol (and very similar to XML-RPC),
defining only a handful of data types and
commands.
JSON-RPC
Sample Request:
{
"version": "1.1",
"method": "confirmFruitPurchase",
"id": "194521489",
"params": [
    [ "apple", "orange", "pear" ],
    1.123
]
}




{
"version": "1.1",
"result": "done",
"error": null,
"id": "194521489"
}
JSON-RPC
Sample Request:
{
"version": "1.1",
"method": "confirmFruitPurchase",
"id": "194521489",
"params": [
    [ "apple", "orange", "pear" ],
    1.123
]
}



Sample Response:
{
"version": "1.1",
"result": "done",
"error": null,
"id": "194521489"
}
Types of APIs
Types of APIs
XML-RPC

SOAP

JSON-RPC
Types of APIs
XML-RPC

SOAP          Service Oriented
JSON-RPC
Types of APIs
XML-RPC

SOAP          Service Oriented
JSON-RPC

REST          Resource Oriented
Types of APIs
   XML-RPC

   SOAP               Service Oriented
   JSON-RPC

   REST                Resource Oriented

Service Oriented architectures are designed
to call methods. REST transports resources.
REST
Representational State Transfer
Guiding Principles
Identification of resources

Manipulation of resources through these
representations

Self-descriptive messages

Hypermedia as the Engine of Application
State (HATEOAS)
Identification of resources
  Individual resources are identified in
  requests, for example using URIs in web-
  based REST systems
Identification of resources
  Individual resources are identified in
  requests, for example using URIs in web-
  based REST systems

  http://api.myapi.com/article/12
Identification of resources
  Individual resources are identified in
  requests, for example using URIs in web-
  based REST systems

  http://api.myapi.com/article/12
  http://api.myapi.com/articles
Identification of resources
  Individual resources are identified in
  requests, for example using URIs in web-
  based REST systems

  http://api.myapi.com/article/12
  http://api.myapi.com/articles
  http://api.myapi.com/customer/4/order/18
Manipulation of resources
Manipulation of resources
  GET

  Return representation of the resource
  requested
Manipulation of resources
  GET

  Return representation of the resource
  requested

  PUT

  Replace representation with new
  representation, or create if does not exist
Manipulation of resources
Manipulation of resources
  POST

  Create a new resource
Manipulation of resources
  POST

  Create a new resource

  DELETE

  Delete the resource
Self-descriptive messages
 Each message includes enough information to
 describe how to process the message

 For example, the specification of media type
 through the use of the Content-Type header
Self-descriptive messages
   Each message includes enough information to
   describe how to process the message

   For example, the specification of media type
   through the use of the Content-Type header

Content-Type: image/jpeg
Self-descriptive messages
    Each message includes enough information to
    describe how to process the message

    For example, the specification of media type
    through the use of the Content-Type header

Content-Type: image/jpeg

                                  <radius>2</radius>
Content-Type: application/xml     <unit>inches</unit>
Self-descriptive messages
Another example are the Response Codes:
   200 Okay               413 Request Entity Too Large

   201 Created            415 Unsupported Media Type

   303 See Other          416 Requested Range Not Satisfiable

   401 Unauthorized       501 Not Implemented

   404 Not Found          many others
HATEOAS
HATEOAS
Just like with HTTP, there is no maintenance
of application state.
HATEOAS
Just like with HTTP, there is no maintenance
of application state.

Cookies are bad! Very, very bad!!
HATEOAS
Just like with HTTP, there is no maintenance
of application state.

Cookies are bad! Very, very bad!!

Related URIs should be included in
representations of resources.
Live Examples!
Other ways to interact
 with a REST service
Other ways to interact
 with a REST service
OPTIONS

Discover which methods of manipulation are
available for specified resource
Other ways to interact
 with a REST service
OPTIONS

Discover which methods of manipulation are
available for specified resource

HEAD

Get sample of Response header without data
payload
Conversation Starters
REST is a set of principles
 and not a specification
How do you specify
format of response?
How do you specify
 format of response?
Content-Type header
How do you specify
 format of response?
Content-Type header

Parameter passed in the URI

http://api.myapi.com/orders?format=text/xml
Allow for differing Accept
 and Content-Type values
 Content-Type: application/xml

 Accept: text/javascript
Represent headers in
  response payload
Status Code: 200 OK
Date: Wed, 16 Mar 2011 17:31:39 GMT
Vary: Accept
Content-Length: 512
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/xml

<?xml version="1.0" encoding="UTF-8"?>
<response>

 <headers>

 
 <ResponseCode>200</ResponseCode>

 
 <Vary>Accept</Vary>

 </headers>

 <country>

 
 <id>1</id>

 
 <name>United States of America</name>

 
 <regionCode>US</regionCode>

 
 <callingPrefix>011</callingPrefix>

 
 <callingCode>1</callingCode>

 </country>
</response>
http://www.aisee.com/graph_of_the_month/http.png
Versioning of resources
There are really only two
 ways to implement the
  concept of versioning:
 use of HTTP headers

 through the syntax of the URI
HTTP Headers
Content-Type: application/vnd.mycompany.myapp+xml

Content-Type: application/vnd.mycompany.myapp2+xml



X-API-Version: 2.0
URI Syntax
api.mysite.com/articles?version=2

api.mysite.com/v2/articles
But what are we
     really versioning?
Representation of our resources?

Our application’s business logic?
Should be our application’s business
logic, but you cannot ignore changes
to the resource’s representation
either.
Suggest use of [Major].[Minor].[Revision]
         api.mysite.com/v1.4.7/articles


! ! Major!- change to business process

! ! Minor!- change to representation

Revision! - syntax corrections
REST API implemented
 in Zend Framework

 https://github.com/notmessenger
Thank You
  Jeremy Brown
notmessenger.com

Contenu connexe

Tendances

RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座Li Yi
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServicesPrateek Tandon
 
Rest presentation
Rest  presentationRest  presentation
Rest presentationsrividhyau
 
RESTful services
RESTful servicesRESTful services
RESTful servicesgouthamrv
 
Restful webservice
Restful webserviceRestful webservice
Restful webserviceDong Ngoc
 
Representational State Transfer (REST)
Representational State Transfer (REST)Representational State Transfer (REST)
Representational State Transfer (REST)David Krmpotic
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraintInviqa
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring FrameworkArcadian Learning
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful ArchitectureKabir Baidya
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJerry Kurian
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTelliando dias
 
RESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RSCarol McDonald
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding RESTNitin Pande
 

Tendances (20)

RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座RESTful SOA - 中科院暑期讲座
RESTful SOA - 中科院暑期讲座
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
Representational State Transfer (REST)
Representational State Transfer (REST)Representational State Transfer (REST)
Representational State Transfer (REST)
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
RESTful Architecture
RESTful ArchitectureRESTful Architecture
RESTful Architecture
 
JAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with JavaJAX-RS. Developing RESTful APIs with Java
JAX-RS. Developing RESTful APIs with Java
 
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 with JAX-RS
RESTful Web Services with JAX-RSRESTful Web Services with JAX-RS
RESTful Web Services with JAX-RS
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Understanding REST
Understanding RESTUnderstanding REST
Understanding REST
 

En vedette

En vedette (20)

Noticias Tel abr2011
Noticias Tel abr2011Noticias Tel abr2011
Noticias Tel abr2011
 
C:\Documents And Settings\Ch13897\Desktop\Dvs 1608 1983 E
C:\Documents And Settings\Ch13897\Desktop\Dvs 1608 1983 EC:\Documents And Settings\Ch13897\Desktop\Dvs 1608 1983 E
C:\Documents And Settings\Ch13897\Desktop\Dvs 1608 1983 E
 
Venus
VenusVenus
Venus
 
Arion
ArionArion
Arion
 
Arion
ArionArion
Arion
 
Infosat
InfosatInfosat
Infosat
 
Library Project Stored Procs
Library Project Stored ProcsLibrary Project Stored Procs
Library Project Stored Procs
 
Thelma & Louise & Lord of the Rings
Thelma & Louise & Lord of the RingsThelma & Louise & Lord of the Rings
Thelma & Louise & Lord of the Rings
 
Kaifa
KaifaKaifa
Kaifa
 
Ecolibrary
EcolibraryEcolibrary
Ecolibrary
 
Pcc Brochure Italian
Pcc Brochure  ItalianPcc Brochure  Italian
Pcc Brochure Italian
 
Dvbshop
DvbshopDvbshop
Dvbshop
 
Pasat
PasatPasat
Pasat
 
Dishpointer
DishpointerDishpointer
Dishpointer
 
You can do this we can help
You can do this we  can helpYou can do this we  can help
You can do this we can help
 
201610무들배지시스템
201610무들배지시스템201610무들배지시스템
201610무들배지시스템
 
Plumbing And Heating
Plumbing And HeatingPlumbing And Heating
Plumbing And Heating
 
Power Point Ap
Power Point ApPower Point Ap
Power Point Ap
 
Sedaj tudi Facebook s svojo "trgovino" aplikacij._Marketing Magazin_jun2012_s...
Sedaj tudi Facebook s svojo "trgovino" aplikacij._Marketing Magazin_jun2012_s...Sedaj tudi Facebook s svojo "trgovino" aplikacij._Marketing Magazin_jun2012_s...
Sedaj tudi Facebook s svojo "trgovino" aplikacij._Marketing Magazin_jun2012_s...
 
3sixtycom credentials new
3sixtycom credentials new3sixtycom credentials new
3sixtycom credentials new
 

Similaire à A Conversation About REST - Extended Version

A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About RESTJeremy Brown
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Jackson F. de A. Mafra
 
Software performance testing_overview
Software performance testing_overviewSoftware performance testing_overview
Software performance testing_overviewRohan Bhattarai
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using PhpSudheer Satyanarayana
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful FundamentalsSuresh Madhra
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIsAparna Sharma
 
Api design and development
Api design and developmentApi design and development
Api design and developmentoquidave
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 

Similaire à A Conversation About REST - Extended Version (20)

A Conversation About REST
A Conversation About RESTA Conversation About REST
A Conversation About REST
 
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Software performance testing_overview
Software performance testing_overviewSoftware performance testing_overview
Software performance testing_overview
 
WebApp #3 : API
WebApp #3 : APIWebApp #3 : API
WebApp #3 : API
 
Building Restful Applications Using Php
Building Restful Applications Using PhpBuilding Restful Applications Using Php
Building Restful Applications Using Php
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
Restful Fundamentals
Restful FundamentalsRestful Fundamentals
Restful Fundamentals
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIs
 
Api design and development
Api design and developmentApi design and development
Api design and development
 
SOA and web services
SOA and web servicesSOA and web services
SOA and web services
 
Api 101
Api 101Api 101
Api 101
 
Soap UI and postman
Soap UI and postmanSoap UI and postman
Soap UI and postman
 
Best Practices in Api Design
Best Practices in Api DesignBest Practices in Api Design
Best Practices in Api Design
 
Rest web service
Rest web serviceRest web service
Rest web service
 
Web Service
Web ServiceWeb Service
Web Service
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 

Dernier

Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in PhilippinesDavidSamuel525586
 
Salesforce Education Cloud - A Complete Guide.pdf
Salesforce Education Cloud - A Complete Guide.pdfSalesforce Education Cloud - A Complete Guide.pdf
Salesforce Education Cloud - A Complete Guide.pdfHarryJohnson78
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024Adnet Communications
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfJamesConcepcion7
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSendBig4
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckHajeJanKamps
 
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdfChris Skinner
 
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOnemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOne Monitar
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFChandresh Chudasama
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdfChris Skinner
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
WSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfWSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfJamesConcepcion7
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdfShaun Heinrichs
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...ssuserf63bd7
 
Introducing the Analogic framework for business planning applications
Introducing the Analogic framework for business planning applicationsIntroducing the Analogic framework for business planning applications
Introducing the Analogic framework for business planning applicationsKnowledgeSeed
 
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdftrending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdfMintel Group
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 

Dernier (20)

Entrepreneurship lessons in Philippines
Entrepreneurship lessons in  PhilippinesEntrepreneurship lessons in  Philippines
Entrepreneurship lessons in Philippines
 
Salesforce Education Cloud - A Complete Guide.pdf
Salesforce Education Cloud - A Complete Guide.pdfSalesforce Education Cloud - A Complete Guide.pdf
Salesforce Education Cloud - A Complete Guide.pdf
 
TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024TriStar Gold Corporate Presentation - April 2024
TriStar Gold Corporate Presentation - April 2024
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
WSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdfWSMM Media and Entertainment Feb_March_Final.pdf
WSMM Media and Entertainment Feb_March_Final.pdf
 
Send Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.comSend Files | Sendbig.com
Send Files | Sendbig.comSend Files | Sendbig.com
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deck
 
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
20220816-EthicsGrade_Scorecard-JP_Morgan_Chase-Q2-63_57.pdf
 
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring CapabilitiesOnemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
Onemonitar Android Spy App Features: Explore Advanced Monitoring Capabilities
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDF
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf20200128 Ethical by Design - Whitepaper.pdf
20200128 Ethical by Design - Whitepaper.pdf
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
WSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdfWSMM Technology February.March Newsletter_vF.pdf
WSMM Technology February.March Newsletter_vF.pdf
 
1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf1911 Gold Corporate Presentation Apr 2024.pdf
1911 Gold Corporate Presentation Apr 2024.pdf
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...
Intermediate Accounting, Volume 2, 13th Canadian Edition by Donald E. Kieso t...
 
Introducing the Analogic framework for business planning applications
Introducing the Analogic framework for business planning applicationsIntroducing the Analogic framework for business planning applications
Introducing the Analogic framework for business planning applications
 
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdftrending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
trending-flavors-and-ingredients-in-salty-snacks-us-2024_Redacted-V2.pdf
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 

A Conversation About REST - Extended Version

  • 1. A Conversation About REST Jeremy Brown notmessenger.com
  • 2. What is an API?
  • 3. What is an API? From Wikipedia: An application programming interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another software program that implements the API.
  • 4. What is an API? Wikipedia continues: It serves as an interface between different software programs and facilitates their interaction, similar to the way the user interface facilitates interaction between humans and computers.
  • 5. What is an API? Our understanding: Set of rules and specifications to facilitate the interaction between different software programs.
  • 7. Types of APIs XML-RPC (1998) SOAP (1998, 2003) JSON-RPC (2005) REST (2000)
  • 8. XML-RPC xmlrpc.com It’s remote procedure calling using HTTP as the transport and XML as the encoding. XML-RPC is designed to be as simple as possible, while allowing complex data structures to be transmitted, processed and returned.
  • 9. XML-RPC xmlrpc.com also says: We wanted a clean, extensible format that’s very simple. It should be possible for an HTML coder to be able to look at a file containing an XML-RPC call, understand what it’s doing, and be able to modify it and have it work on the first or second try... We also wanted it to be an easy protocol that could quickly be adapted to run in other environments or on other operating systems.
  • 10. XML-RPC Sample Request: <?xml version="1.0"?> <methodCall> <methodName>getStateName</methodName> <params> <param> <value><int>40</int></value> </param> </params> </methodCall>
  • 11. XML-RPC Sample Request: <?xml version="1.0"?> <methodCall> <methodName>getStateName</methodName> <params> <param> <value><int>40</int></value> </param> </params> </methodCall> Sample Response: <?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
  • 12. SOAP SOAP spec: SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses.
  • 13. SOAP Sample Request: POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: 299 <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header> </soap:Header> <soap:Body> <m:GetStockPrice xmlns:m="http://www.example.org/stock"> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
  • 14. JSON-RPC Wikipedia says: JSON-RPC is a remote procedure call protocol encoded in JSON. It is a very simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands.
  • 15. JSON-RPC Sample Request: { "version": "1.1", "method": "confirmFruitPurchase", "id": "194521489", "params": [ [ "apple", "orange", "pear" ], 1.123 ] } { "version": "1.1", "result": "done", "error": null, "id": "194521489" }
  • 16. JSON-RPC Sample Request: { "version": "1.1", "method": "confirmFruitPurchase", "id": "194521489", "params": [ [ "apple", "orange", "pear" ], 1.123 ] } Sample Response: { "version": "1.1", "result": "done", "error": null, "id": "194521489" }
  • 19. Types of APIs XML-RPC SOAP Service Oriented JSON-RPC
  • 20. Types of APIs XML-RPC SOAP Service Oriented JSON-RPC REST Resource Oriented
  • 21. Types of APIs XML-RPC SOAP Service Oriented JSON-RPC REST Resource Oriented Service Oriented architectures are designed to call methods. REST transports resources.
  • 23. Guiding Principles Identification of resources Manipulation of resources through these representations Self-descriptive messages Hypermedia as the Engine of Application State (HATEOAS)
  • 24. Identification of resources Individual resources are identified in requests, for example using URIs in web- based REST systems
  • 25. Identification of resources Individual resources are identified in requests, for example using URIs in web- based REST systems http://api.myapi.com/article/12
  • 26. Identification of resources Individual resources are identified in requests, for example using URIs in web- based REST systems http://api.myapi.com/article/12 http://api.myapi.com/articles
  • 27. Identification of resources Individual resources are identified in requests, for example using URIs in web- based REST systems http://api.myapi.com/article/12 http://api.myapi.com/articles http://api.myapi.com/customer/4/order/18
  • 29. Manipulation of resources GET Return representation of the resource requested
  • 30. Manipulation of resources GET Return representation of the resource requested PUT Replace representation with new representation, or create if does not exist
  • 32. Manipulation of resources POST Create a new resource
  • 33. Manipulation of resources POST Create a new resource DELETE Delete the resource
  • 34. Self-descriptive messages Each message includes enough information to describe how to process the message For example, the specification of media type through the use of the Content-Type header
  • 35. Self-descriptive messages Each message includes enough information to describe how to process the message For example, the specification of media type through the use of the Content-Type header Content-Type: image/jpeg
  • 36. Self-descriptive messages Each message includes enough information to describe how to process the message For example, the specification of media type through the use of the Content-Type header Content-Type: image/jpeg <radius>2</radius> Content-Type: application/xml <unit>inches</unit>
  • 37. Self-descriptive messages Another example are the Response Codes: 200 Okay 413 Request Entity Too Large 201 Created 415 Unsupported Media Type 303 See Other 416 Requested Range Not Satisfiable 401 Unauthorized 501 Not Implemented 404 Not Found many others
  • 39. HATEOAS Just like with HTTP, there is no maintenance of application state.
  • 40. HATEOAS Just like with HTTP, there is no maintenance of application state. Cookies are bad! Very, very bad!!
  • 41. HATEOAS Just like with HTTP, there is no maintenance of application state. Cookies are bad! Very, very bad!! Related URIs should be included in representations of resources.
  • 42.
  • 44. Other ways to interact with a REST service
  • 45. Other ways to interact with a REST service OPTIONS Discover which methods of manipulation are available for specified resource
  • 46. Other ways to interact with a REST service OPTIONS Discover which methods of manipulation are available for specified resource HEAD Get sample of Response header without data payload
  • 48. REST is a set of principles and not a specification
  • 49. How do you specify format of response?
  • 50. How do you specify format of response? Content-Type header
  • 51. How do you specify format of response? Content-Type header Parameter passed in the URI http://api.myapi.com/orders?format=text/xml
  • 52. Allow for differing Accept and Content-Type values Content-Type: application/xml Accept: text/javascript
  • 53. Represent headers in response payload Status Code: 200 OK Date: Wed, 16 Mar 2011 17:31:39 GMT Vary: Accept Content-Length: 512 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/xml <?xml version="1.0" encoding="UTF-8"?> <response> <headers> <ResponseCode>200</ResponseCode> <Vary>Accept</Vary> </headers> <country> <id>1</id> <name>United States of America</name> <regionCode>US</regionCode> <callingPrefix>011</callingPrefix> <callingCode>1</callingCode> </country> </response>
  • 56. There are really only two ways to implement the concept of versioning: use of HTTP headers through the syntax of the URI
  • 57. HTTP Headers Content-Type: application/vnd.mycompany.myapp+xml Content-Type: application/vnd.mycompany.myapp2+xml X-API-Version: 2.0
  • 59. But what are we really versioning? Representation of our resources? Our application’s business logic?
  • 60. Should be our application’s business logic, but you cannot ignore changes to the resource’s representation either.
  • 61. Suggest use of [Major].[Minor].[Revision] api.mysite.com/v1.4.7/articles ! ! Major!- change to business process ! ! Minor!- change to representation Revision! - syntax corrections
  • 62. REST API implemented in Zend Framework https://github.com/notmessenger
  • 63. Thank You Jeremy Brown notmessenger.com

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. SOAP - 2003: W3C recommendation submitted. Is NOT a spec.\n
  7. \n
  8. \n
  9. \n
  10. \n
  11. Can be used over SMTP and other protocols because of its design.\n\nIs NOT lightweight.\n\nNothing works out of the box - ever.\n
  12. \n
  13. \n
  14. Required Methods\n\nREQUEST:\n method\n id\n params\n\nRESPONSE:\n result\n error\n id\n
  15. \n
  16. \n
  17. \n
  18. \n
  19. Roy Fielding\n\nCo-authored HTTP 1.0 and 1.1 spec\n\nREST was designed along side HTTP 1.1\n
  20. \n
  21. 2nd one: talk about collections\n\n3rd one: talk about customer/order vs order/customer\n
  22. 2nd one: talk about collections\n\n3rd one: talk about customer/order vs order/customer\n
  23. 2nd one: talk about collections\n\n3rd one: talk about customer/order vs order/customer\n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. Remember PUT? Not all APIs create a new resource.\n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. Order a book\n-----------\nUsed to not get a receipt, but now you do.\nIs a change to the business rules.\nAccomplished by a &amp;#x201C;303 See Other&amp;#x201D; header.\nNo big deal.\n\nPurchasing system\n----------------\nUsed to get back a representation that contained order details, including invoice number.\nNow ability to select payment options is what is served instead (PO #, net 30, etc).\nIs a change to the business rules.\nConsuming client *should* know how to follow links and if just computer-to-computer would be fine.\nBut if GUI, then new user experience needs to be developed.\n\nAddition of email address to customer details\n--------------------------------------\nHad name and phone before.\nNow have added email.\n\n
  51. \n
  52. \n
  53. \n