SlideShare a Scribd company logo
1 of 25
Super simple
introduction to
REST-API’s
For programmers
By Patrick Savalle, innovation architect Delta Lloyd NV.
CONTENTS
1. HTTP-BASICS
2. REST-BASICS
3. API-BASICS
PART 1
HTTP BASICS
REST is HTTP/1.1. It is the native protocol of the web. Advantages are:
• Every tool that can handle Web / HTTP, can handle REST as native
‘content’. For instance gateways, web-servers and browsers can effectively
cache, route, verify, manipulate REST requests or responses.
• In short the whole web supports REST
• It is simple and elegant
• Less diversity in technology, you already use HTTP
Part1:~ Http$ WHY REST?_
REST is HTTP. It is the same protocol.
Created by the same designer.
Part1:~ Http$ PROTOCOL_
HTTP is a plain text conversation between
a client and a server. The conversation is
based on actions performed on resources
which are addressed by URL’s.
Part1:~ Http$ URL_
Every resource has an unique URL that
consists of several parts.
Part1:~ Http$ VERBS_
The actions that can be performed on a resource
are called ‘methods’ or ‘verbs’. Below the most
used verbs (there are many more).
POST – create
PUT – update
DELETE – delete
GET – read
PATCH – partial update
TRACE – echo
HEAD – headers only
Part1:~ Http$ Request_
Requests and responses contain header-fields
and possibly ‘content’. Everything is plain text.
Headers usually contain metadata or indicate
conversation preferences.
AUTHENTICATION
Part1:~ Http$ JSON RESPONSE_
Part1:~ Http$ STATUS CODES_
Every response contains a status code.
PART 2
REST BASICS
Part2:~ Rest$ ENDPOINTS_
The REST protocol is based on ‘endpoints’, which are
operations on resources addressed by URL’s.
Endpoints can be bundled to form an API.
ACTION RESOURCE
<verb> https://<host>/<api_version>[/<resource_type>/<instance_id>]
GET https://animal.api/1/lions (returns collection)
GET https://animal.api/1/lions/harry@lion.com (returns single lion)
POST https://animal.api/1/lions (create new element)
PUT https://animal.api/1/lions/harry@lion.com (updates element)
PATCH https://animal.api/1/lions/harry@lion.com (partial update)
DELETE https://animal.api/1/lions (deletes collection)
DELETE https://animal.api/1/lions/harry@lion.com (deletes single element)
GET http://www.example.com/1/customers/33245/orders/8769/lineitems/1
GET https://animal.api/1/lions?start=100&count=50
GET https://animal.api/1/lions?id=100&id=103&id=107 (parameter-array)
Part2:~ Rest$ ACTION + RESOURCE_
An endpoint has a very strict URL structure. This is key to
‘REST’. Map your functional application resources onto the
WWW and allow them to be manipulated.
Part2:~ Rest$ ANTI-PATTERNS_
REST is not SOAP.
An URL is NOT a RPC-address or method,
it is an universal RESOURCE locator
Bad REST API (bad URL’s in general):
POST https://domain.com/updateProfile
POST https://domain.com/deleteProfile
POST https://domain.com/createProfile
Good REST API:
PUT https://domain.com/1/profiles/piet@puk.com
DELETE https://domain.com/1/profiles/piet@puk.com
POST https://domain.com/1/profiles
GET https://domain.com/1/profiles/piet@puk.com
AUTHENTICATION
• HTTP BASIC AUTH
Client sends user/password in special header with each API-call. Simple,
safe, good choice for API-2-API
• TOKEN AUTH
Get a temporary access token from API, use in API-calls in username part
of HTTP BACIS AUTH, simple, safe, good choice for WEB-2-API
• OAUTH2
Industry standard. Flexible. Safe.
Part2:~ Rest$ AUTHENTICATION_
Part2:~ Rest$ JAVA EXAMPLE_
HttpResponse<JsonNode> jsonResponse =
Unirest
.post("http://httpbin.org/post")
.header("accept", "application/json")
.queryString("apiKey", "123")
.field("parameter", "value")
.field("foo", "bar")
.asJson();
PART 3
API BASICS
Part3:~ Api$ RULE NUMBER ONE_
A REST-server must be client-state agnostic!
To be flexible and scalable the server needs to be ignorant of client-state or
context. A REST-server does not store session data on behalf of the client.
Put another way: all necessary context MUST be in the request. As far as the
REST-server is concerned every call is the first call.
Part3:~ Api$ Economy_
There is an API for that. REST-API’s are the
glue of the Internet of Things.
Possible clients of your API:
• Other API’s
• Web applications and web front ends (like AngularJS, ReactJS, JQuery web
apps)
• Mobile app’s, applications etc.
• Machines, bots
• Typically NOT humans or ‘end users’
API’s are the glue of the internet of things (IoT).
Part3:~ Api$ Users_
On the internet nobody knows you’re a machine.
• Coherent
• Cohesive (Only lists purposeful endpoints)
• Complete (has all necessary endpoints for its purpose)
• Minimal (Only one way to do things)
• Encapsulating (hiding implementation details)
• Self-explaining
• Documented!
 Design an API ‘outside-in’, as a product for a generic client. Not just as
the library for your specific front-end.
 Consider adding the role ‘interface designer’ to the team.
Part3:~ Api$ Interface quality_
Good interface design is crafmanship.
• The API
• Endpoint documentation
• A dashboard to register apps / obtain an API-key
• Language stubs (Java, PHP, Python, etc.) on Github
• Registration on programmableweb and similar
• A homepage / productpage
• A revenue-model / pricing
• A launchparty
• Hackathons
Part3:~ Api$ deliverables_
An API is a product, treat it as such.
Some of the choices only you can make:
• Few methods / large responses vs. many methods / small responses
Considerations: web clients generally like large aggregated responses tailored to their
page structures. Other clients like smaller responses. Etc. There is also the underlying
(logical) data model and the ‘natural granularity’ of the problem-domain. In most cases:
map the data model onto URL’s.
• URL parameters vs request headers (for instance the API-tokens)
Considerations: in general non-functional data should be in headers. Headers are more
easily inspected / used by tools like webservers, giving transport flexibility.
• Hypermedia communication (follow-up URL’s in responses, HATEOAS)
Problematic concept, very client dependent.
Most API’s don’t have this, why should yours?
Part3:~ Api$ Interface choices_
Good interface design is crafmanship.
• A REST client, e.g. the Chrome POSTMAN plugin (most IDE’s have one as
an add-on)
• TELNET (the generic HTTP client)
• http://www.restapitutorial.com/resources.html
• https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md
• http://jsonapi.org/
Part3:~ Api$ RESOURCES_

More Related Content

What's hot

RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 

What's hot (20)

API Design- Best Practices
API Design-   Best PracticesAPI Design-   Best Practices
API Design- Best Practices
 
Introduction to REST - API
Introduction to REST - APIIntroduction to REST - API
Introduction to REST - API
 
Rest API
Rest APIRest API
Rest API
 
API
APIAPI
API
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Api types
Api typesApi types
Api types
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
Web api
Web apiWeb api
Web api
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
What is an API
What is an APIWhat is an API
What is an API
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Testando API REST - Parte 1
Testando API REST - Parte 1Testando API REST - Parte 1
Testando API REST - Parte 1
 
Express JS Rest API Tutorial
Express JS Rest API TutorialExpress JS Rest API Tutorial
Express JS Rest API Tutorial
 
What is API - Understanding API Simplified
What is API - Understanding API SimplifiedWhat is API - Understanding API Simplified
What is API - Understanding API Simplified
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Restful web services ppt
Restful web services pptRestful web services ppt
Restful web services ppt
 
Introduction to API
Introduction to APIIntroduction to API
Introduction to API
 

Viewers also liked

Viewers also liked (6)

The Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReSTThe Internet as Web Services: introduction to ReST
The Internet as Web Services: introduction to ReST
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Introduction To REST
Introduction To RESTIntroduction To REST
Introduction To REST
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
HATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API StyleHATEOAS 101 - Opinionated Introduction to a REST API Style
HATEOAS 101 - Opinionated Introduction to a REST API Style
 
REST Presentation
REST PresentationREST Presentation
REST Presentation
 

Similar to REST-API introduction for developers

Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financial
Rule_Financial
 

Similar to REST-API introduction for developers (20)

Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
REST-API's for architects and managers
REST-API's for architects and managersREST-API's for architects and managers
REST-API's for architects and managers
 
Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2Service approach for development Rest API in Symfony2
Service approach for development Rest API in Symfony2
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
Restful web services rule financial
Restful web services   rule financialRestful web services   rule financial
Restful web services rule financial
 
REST APIs
REST APIsREST APIs
REST APIs
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Day02 a pi.
Day02   a pi.Day02   a pi.
Day02 a pi.
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Creating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APICreating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services API
 
RoR guide_p1
RoR guide_p1RoR guide_p1
RoR guide_p1
 
Web services - REST and SOAP
Web services - REST and SOAPWeb services - REST and SOAP
Web services - REST and SOAP
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
Java part 3
Java part  3Java part  3
Java part 3
 
Creating a RESTful api without losing too much sleep
Creating a RESTful api without losing too much sleepCreating a RESTful api without losing too much sleep
Creating a RESTful api without losing too much sleep
 
Getting Started with Rails
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
 
RESTful web APIs (build, document, manage)
RESTful web APIs (build, document, manage)RESTful web APIs (build, document, manage)
RESTful web APIs (build, document, manage)
 

More from Patrick Savalle

The future of work, a whitepaper
The future of work, a whitepaperThe future of work, a whitepaper
The future of work, a whitepaper
Patrick Savalle
 

More from Patrick Savalle (15)

REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / concepts
 
REST-API design patterns
REST-API design patternsREST-API design patterns
REST-API design patterns
 
State of technology and innovation (2017 edition)
State of technology and innovation  (2017 edition)State of technology and innovation  (2017 edition)
State of technology and innovation (2017 edition)
 
A bitcoin and blockchain primer
A bitcoin and blockchain primerA bitcoin and blockchain primer
A bitcoin and blockchain primer
 
A quick review of (near future) disruptions and innovations.
A quick review of (near future) disruptions and innovations.A quick review of (near future) disruptions and innovations.
A quick review of (near future) disruptions and innovations.
 
Bitcoin presentation deltalloyd
Bitcoin presentation deltalloydBitcoin presentation deltalloyd
Bitcoin presentation deltalloyd
 
The future of work, a whitepaper
The future of work, a whitepaperThe future of work, a whitepaper
The future of work, a whitepaper
 
TeamPark book (english) part 1, vision and inspiration
TeamPark book (english)  part 1, vision and inspirationTeamPark book (english)  part 1, vision and inspiration
TeamPark book (english) part 1, vision and inspiration
 
TeamPark book (english) part 2, platform and method
TeamPark book (english)   part 2, platform and methodTeamPark book (english)   part 2, platform and method
TeamPark book (english) part 2, platform and method
 
TeamPark: platform en methode
TeamPark: platform en methodeTeamPark: platform en methode
TeamPark: platform en methode
 
TeamPark: inspiratie en visie
TeamPark: inspiratie en visieTeamPark: inspiratie en visie
TeamPark: inspiratie en visie
 
Social Platform Design
Social Platform DesignSocial Platform Design
Social Platform Design
 
Build the socially integrated organization with the TeamPark-method
Build the socially integrated organization with the TeamPark-methodBuild the socially integrated organization with the TeamPark-method
Build the socially integrated organization with the TeamPark-method
 
TeamPark: Alternatieve presentatie (NL)
TeamPark: Alternatieve presentatie (NL)TeamPark: Alternatieve presentatie (NL)
TeamPark: Alternatieve presentatie (NL)
 
Building Intelligent Organizations with Sogeti TeamPark
Building Intelligent Organizations with Sogeti TeamParkBuilding Intelligent Organizations with Sogeti TeamPark
Building Intelligent Organizations with Sogeti TeamPark
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Recently uploaded (20)

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

REST-API introduction for developers

  • 1. Super simple introduction to REST-API’s For programmers By Patrick Savalle, innovation architect Delta Lloyd NV.
  • 2.
  • 5. REST is HTTP/1.1. It is the native protocol of the web. Advantages are: • Every tool that can handle Web / HTTP, can handle REST as native ‘content’. For instance gateways, web-servers and browsers can effectively cache, route, verify, manipulate REST requests or responses. • In short the whole web supports REST • It is simple and elegant • Less diversity in technology, you already use HTTP Part1:~ Http$ WHY REST?_ REST is HTTP. It is the same protocol. Created by the same designer.
  • 6. Part1:~ Http$ PROTOCOL_ HTTP is a plain text conversation between a client and a server. The conversation is based on actions performed on resources which are addressed by URL’s.
  • 7. Part1:~ Http$ URL_ Every resource has an unique URL that consists of several parts.
  • 8. Part1:~ Http$ VERBS_ The actions that can be performed on a resource are called ‘methods’ or ‘verbs’. Below the most used verbs (there are many more). POST – create PUT – update DELETE – delete GET – read PATCH – partial update TRACE – echo HEAD – headers only
  • 9. Part1:~ Http$ Request_ Requests and responses contain header-fields and possibly ‘content’. Everything is plain text. Headers usually contain metadata or indicate conversation preferences.
  • 11. Part1:~ Http$ STATUS CODES_ Every response contains a status code.
  • 13. Part2:~ Rest$ ENDPOINTS_ The REST protocol is based on ‘endpoints’, which are operations on resources addressed by URL’s. Endpoints can be bundled to form an API.
  • 14. ACTION RESOURCE <verb> https://<host>/<api_version>[/<resource_type>/<instance_id>] GET https://animal.api/1/lions (returns collection) GET https://animal.api/1/lions/harry@lion.com (returns single lion) POST https://animal.api/1/lions (create new element) PUT https://animal.api/1/lions/harry@lion.com (updates element) PATCH https://animal.api/1/lions/harry@lion.com (partial update) DELETE https://animal.api/1/lions (deletes collection) DELETE https://animal.api/1/lions/harry@lion.com (deletes single element) GET http://www.example.com/1/customers/33245/orders/8769/lineitems/1 GET https://animal.api/1/lions?start=100&count=50 GET https://animal.api/1/lions?id=100&id=103&id=107 (parameter-array) Part2:~ Rest$ ACTION + RESOURCE_ An endpoint has a very strict URL structure. This is key to ‘REST’. Map your functional application resources onto the WWW and allow them to be manipulated.
  • 15. Part2:~ Rest$ ANTI-PATTERNS_ REST is not SOAP. An URL is NOT a RPC-address or method, it is an universal RESOURCE locator Bad REST API (bad URL’s in general): POST https://domain.com/updateProfile POST https://domain.com/deleteProfile POST https://domain.com/createProfile Good REST API: PUT https://domain.com/1/profiles/piet@puk.com DELETE https://domain.com/1/profiles/piet@puk.com POST https://domain.com/1/profiles GET https://domain.com/1/profiles/piet@puk.com
  • 16. AUTHENTICATION • HTTP BASIC AUTH Client sends user/password in special header with each API-call. Simple, safe, good choice for API-2-API • TOKEN AUTH Get a temporary access token from API, use in API-calls in username part of HTTP BACIS AUTH, simple, safe, good choice for WEB-2-API • OAUTH2 Industry standard. Flexible. Safe. Part2:~ Rest$ AUTHENTICATION_
  • 17. Part2:~ Rest$ JAVA EXAMPLE_ HttpResponse<JsonNode> jsonResponse = Unirest .post("http://httpbin.org/post") .header("accept", "application/json") .queryString("apiKey", "123") .field("parameter", "value") .field("foo", "bar") .asJson();
  • 19. Part3:~ Api$ RULE NUMBER ONE_ A REST-server must be client-state agnostic! To be flexible and scalable the server needs to be ignorant of client-state or context. A REST-server does not store session data on behalf of the client. Put another way: all necessary context MUST be in the request. As far as the REST-server is concerned every call is the first call.
  • 20. Part3:~ Api$ Economy_ There is an API for that. REST-API’s are the glue of the Internet of Things.
  • 21. Possible clients of your API: • Other API’s • Web applications and web front ends (like AngularJS, ReactJS, JQuery web apps) • Mobile app’s, applications etc. • Machines, bots • Typically NOT humans or ‘end users’ API’s are the glue of the internet of things (IoT). Part3:~ Api$ Users_ On the internet nobody knows you’re a machine.
  • 22. • Coherent • Cohesive (Only lists purposeful endpoints) • Complete (has all necessary endpoints for its purpose) • Minimal (Only one way to do things) • Encapsulating (hiding implementation details) • Self-explaining • Documented!  Design an API ‘outside-in’, as a product for a generic client. Not just as the library for your specific front-end.  Consider adding the role ‘interface designer’ to the team. Part3:~ Api$ Interface quality_ Good interface design is crafmanship.
  • 23. • The API • Endpoint documentation • A dashboard to register apps / obtain an API-key • Language stubs (Java, PHP, Python, etc.) on Github • Registration on programmableweb and similar • A homepage / productpage • A revenue-model / pricing • A launchparty • Hackathons Part3:~ Api$ deliverables_ An API is a product, treat it as such.
  • 24. Some of the choices only you can make: • Few methods / large responses vs. many methods / small responses Considerations: web clients generally like large aggregated responses tailored to their page structures. Other clients like smaller responses. Etc. There is also the underlying (logical) data model and the ‘natural granularity’ of the problem-domain. In most cases: map the data model onto URL’s. • URL parameters vs request headers (for instance the API-tokens) Considerations: in general non-functional data should be in headers. Headers are more easily inspected / used by tools like webservers, giving transport flexibility. • Hypermedia communication (follow-up URL’s in responses, HATEOAS) Problematic concept, very client dependent. Most API’s don’t have this, why should yours? Part3:~ Api$ Interface choices_ Good interface design is crafmanship.
  • 25. • A REST client, e.g. the Chrome POSTMAN plugin (most IDE’s have one as an add-on) • TELNET (the generic HTTP client) • http://www.restapitutorial.com/resources.html • https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md • http://jsonapi.org/ Part3:~ Api$ RESOURCES_

Editor's Notes

  1. Voorbeeld van een set REST-API methode. Deze is geprogrammeerd in PHP 7.1 en je ziet de automatisch gegenereerde quick reference op de root van het API-domein.
  2. In the basis HTTP is a text oriented protocol. You can use TELNET to construct and send requests.
  3. Verbs indicate the action on the URL in the request. All verbs: https://www.iana.org/assignments/http-methods/http-methods.xhtml