SlideShare a Scribd company logo
An Introduction to
REST API
Presented By:
Aniruddh Bhilvare
22 April, 2017
What is it ?
API
WEB
URL
HTTP
GET
INTERNET
JSON
REQUEST
HEADER
POST
RESPONSE
METHOD
RESPONSE
What is it ?
REST means
REpresentational
State
Transfer
REpresentational ? State ? Transfer ?
It represent the state of database at a time. But how???
REST is an architectural style which is based on web-standards and the
HTTP protocol.
In a REST based architecture everything is a Resource.
A resource is accessed via a common interface based on the HTTP standard
methods.
You typically have a REST server which provides access to the resources and
a REST client which accesses and modifies the REST resources.
REpresentational ? State ? Transfer ?
Every resource should support the HTTP common operations.
Resources are identified by global IDs (which are typically URIs or URLs).
REST allows that resources have different representations, e.g., text, XML,
JSON etc.
Stateless in nature. Excellent for distributed system.
Stateless components can be freely redeployed if something fails, and they
can scale to accommodate load changes.
This is because any request can be directed to any instance of a component.
HTTP Methods
The PUT, GET, POST and DELETE methods are typically used in REST based
architectures. The following table gives an explanation of these operations:
HTTP Method CRUD Operation Description
POST INSERT Addes to an existing resource
PUT UPDATE Overrides existing resource
GET SELECT Fetches a resource. The resource is
never changed via a GET request
DELETE DELETE Deletes a resource
Architecture:
HTTP Request Example:
HTTP Response Example:
HTTP REST Request:
HTTP REST API Request
GET https://www.myhost.com/api/v1/user/1/cities
Read, All the cities for user whose id is 1
GET /user/1/cities http/1.1
host: https://www.myhost.com/api/v1
Content-Type: application/json
Accept-Language: us-en
state_id: 2
HTTP REST Response:
HTTP REST API Response
HTTP/1.1 200 OK (285ms)
Date: Fri, 21 Apr 2017 10:27:20 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/7.0.16
X-Powered-By: PHP/7.0.16
Content-Length: 109
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
{"status":"success","message":"City
List","data":[{"city_name":"Visakhapatnam"},{"city_name":"Vijayawada"}]}
HTTP Response Status Code:
1xx Informational Codes
2xx Successful Codes
3xx Redirection Codes
4xx Client Error Code
5xx Server Error Codes
List at here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Points to be noted
For REST APIs
Use Nouns but no verbs in path/URI:
Purpose Method Incorrect Correct
Retrieves a list of users GET /getAllCars /users
Create a new user POST /createUser /users
Delete a user DELETE /deleteUser /users/10
Get balance of user GET /getUserBalance /users/11/balance
Use plural nouns:
Do not mix up singular and plural nouns. Keep it simple and use only plural
nouns for all resources.
/cars instead of /car
/users instead of /user
/products instead of /product
/settings instead of /setting
GET method should not alter the state:
Use PUT, POST and DELETE methods instead of the GET method to alter
the state.
Do not use GET method or Query parameters for state changes:
GET /users/711?activate or
GET /users/711/activate
Use sub-resources for relation:
If a resource is related to another resource use subresources
GET /cars/711/drivers/ (Returns a list of drivers for car 711)
GET /cars/711/drivers/4 (Returns driver #4 for car 711)
Use HTTP headers for serialization formats:
Both, client and server need to know which format is used for the
communication. The format has to be specified in the HTTP-Header.
Content-Type defines the request format.
Accept defines a list of acceptable response formats.
Versioning is important:
Make the API Version mandatory and do not release an unversioned API.
Use a simple ordinal number and avoid dot notation such as 2.5
We are using the url for the API versioning starting with the letter “v”
/blog/api/v1
Handle Errors with HTTP Status code:
200 OK (Everything is working) 403 Forbidden (The server understood the
request, but is refusing it or the access is
not allowed)
201 OK (New resource has been created) 404 Not found (There is no resource behind the
URI)
204 OK (Resource successfully deleted) 405 Method not allowed
400 Bad Request (The request was invalid or
cannot be served. The exact error should
be explained in the error payload. E.g.
„The JSON is not valid“)
408 Request timeout
401 Unauthorized (The request requires an
user authentication)
500 Internal server error
Filtering:
Use a unique query parameter for all fields or a query language for filtering.
GET /cars?color=red (Returns a list of red cars)
GET /users?name=tom (Returns a list of users whose name matches tom)
Sorting:
Allow ascending and descending sorting over multiple fields.
GET /cars?sort=-manufacturer,+model
This returns a list of cars sorted by descending manufacturers and
ascending models)
Paging:
Use limit and offset. It is flexible for the user and common in leading
databases.
The default should be limit=20 and offset=0
GET /cars?offset=10&limit=5
Aliases for common queries:
To make the API experience more pleasant for the average consumer,
consider packaging up sets of conditions into easily accessible RESTful
paths.
For example consider following use case:
POST /users (User Register: Creates a new user)
POST /users/login (User Login: Creates auth token for user authentication)
Want to develop REST APIs easily???
Checkout Slim - A microframework for php.
Documentation: https://www.slimframework.com/docs/
Thanks for your Time & Patience!
Any Question?

More Related Content

What's hot (20)

PPTX
RESTful API - Best Practices
Tricode (part of Dept)
 
PPTX
Introduction to REST - API
Chetan Gadodia
 
PPT
Understanding REST
Nitin Pande
 
PPT
Introduction to the Web API
Brad Genereaux
 
PDF
RESTful Web Services
Christopher Bartling
 
PPTX
REST-API introduction for developers
Patrick Savalle
 
PPTX
ASP.NET Web API
habib_786
 
PPSX
Rest api standards and best practices
Ankita Mahajan
 
PPTX
Api testing
Keshav Kashyap
 
PPTX
Rest api and-crud-api
F(x) Data Labs Pvt Ltd
 
PPTX
Restful web services ppt
OECLIB Odisha Electronics Control Library
 
PPTX
Web api
Sudhakar Sharma
 
PPTX
Design Beautiful REST + JSON APIs
Stormpath
 
PDF
Cross-domain requests with CORS
Vladimir Dzhuvinov
 
PPT
Postman.ppt
ParrotBAD
 
PDF
JavaScript Fetch API
Xcat Liu
 
PDF
Api presentation
Tiago Cardoso
 
PPTX
React.js - The Dawn of Virtual DOM
Jimit Shah
 
PDF
API for Beginners
Gustavo De Vita
 
RESTful API - Best Practices
Tricode (part of Dept)
 
Introduction to REST - API
Chetan Gadodia
 
Understanding REST
Nitin Pande
 
Introduction to the Web API
Brad Genereaux
 
RESTful Web Services
Christopher Bartling
 
REST-API introduction for developers
Patrick Savalle
 
ASP.NET Web API
habib_786
 
Rest api standards and best practices
Ankita Mahajan
 
Api testing
Keshav Kashyap
 
Rest api and-crud-api
F(x) Data Labs Pvt Ltd
 
Design Beautiful REST + JSON APIs
Stormpath
 
Cross-domain requests with CORS
Vladimir Dzhuvinov
 
Postman.ppt
ParrotBAD
 
JavaScript Fetch API
Xcat Liu
 
Api presentation
Tiago Cardoso
 
React.js - The Dawn of Virtual DOM
Jimit Shah
 
API for Beginners
Gustavo De Vita
 

Similar to An Introduction To REST API (20)

PPTX
Http and REST APIs.
Rahul Tanwani
 
PPTX
RESTful Services
Jason Gerard
 
PDF
Алексей Веркеенко "Symfony2 & REST API"
Fwdays
 
PPTX
Rest WebAPI with OData
Mahek Merchant
 
PPTX
rest-api-basics.pptx
AgungSutikno1
 
PPTX
Understanding APIs.pptx
Sherif Ali , MBA , ITIL , IBDL
 
PPTX
Understanding APIs.pptx introduction chk
nooreen nayyar syeda
 
PPTX
Tutorial_Rest_API_For_Beginners_125.pptx
T.Choithram & Sons Dubai
 
PDF
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
PDF
The never-ending REST API design debate
Restlet
 
PPTX
rest-api-basics.pptx
FikiRieza2
 
PDF
REST API Recommendations
Jeelani Shaik
 
PPTX
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
keshabregmi1
 
PDF
REST APIS web development for backend familiarity
ARTUROGOMEZGARCIA2
 
PDF
RefCard RESTful API Design
OCTO Technology
 
PDF
Создание API, которое полюбят разработчики. Глубокое погружение
SQALab
 
ODP
Attacking REST API
Siddharth Bezalwar
 
PDF
Restful api design
Mizan Riqzia
 
PPTX
REST API V2
Дмитрий Бойко
 
Http and REST APIs.
Rahul Tanwani
 
RESTful Services
Jason Gerard
 
Алексей Веркеенко "Symfony2 & REST API"
Fwdays
 
Rest WebAPI with OData
Mahek Merchant
 
rest-api-basics.pptx
AgungSutikno1
 
Understanding APIs.pptx
Sherif Ali , MBA , ITIL , IBDL
 
Understanding APIs.pptx introduction chk
nooreen nayyar syeda
 
Tutorial_Rest_API_For_Beginners_125.pptx
T.Choithram & Sons Dubai
 
The never-ending REST API design debate -- Devoxx France 2016
Restlet
 
The never-ending REST API design debate
Restlet
 
rest-api-basics.pptx
FikiRieza2
 
REST API Recommendations
Jeelani Shaik
 
Building-Robust-APIs-ASPNET-Web-API-and-RESTful-Patterns.pptx
keshabregmi1
 
REST APIS web development for backend familiarity
ARTUROGOMEZGARCIA2
 
RefCard RESTful API Design
OCTO Technology
 
Создание API, которое полюбят разработчики. Глубокое погружение
SQALab
 
Attacking REST API
Siddharth Bezalwar
 
Restful api design
Mizan Riqzia
 
Ad

Recently uploaded (20)

PPTX
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Using Google Data Studio (Looker Studio) to Create Effective and Easy Data Re...
Orage Technologies
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
python advanced data structure dictionary with examples python advanced data ...
sprasanna11
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Using Google Data Studio (Looker Studio) to Create Effective and Easy Data Re...
Orage Technologies
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
OpenInfra ID 2025 - Are Containers Dying? Rethinking Isolation with MicroVMs.pdf
Muhammad Yuga Nugraha
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Ad

An Introduction To REST API

  • 1. An Introduction to REST API Presented By: Aniruddh Bhilvare 22 April, 2017
  • 2. What is it ? API WEB URL HTTP GET INTERNET JSON REQUEST HEADER POST RESPONSE METHOD RESPONSE
  • 3. What is it ? REST means REpresentational State Transfer
  • 4. REpresentational ? State ? Transfer ? It represent the state of database at a time. But how??? REST is an architectural style which is based on web-standards and the HTTP protocol. In a REST based architecture everything is a Resource. A resource is accessed via a common interface based on the HTTP standard methods. You typically have a REST server which provides access to the resources and a REST client which accesses and modifies the REST resources.
  • 5. REpresentational ? State ? Transfer ? Every resource should support the HTTP common operations. Resources are identified by global IDs (which are typically URIs or URLs). REST allows that resources have different representations, e.g., text, XML, JSON etc. Stateless in nature. Excellent for distributed system. Stateless components can be freely redeployed if something fails, and they can scale to accommodate load changes. This is because any request can be directed to any instance of a component.
  • 6. HTTP Methods The PUT, GET, POST and DELETE methods are typically used in REST based architectures. The following table gives an explanation of these operations: HTTP Method CRUD Operation Description POST INSERT Addes to an existing resource PUT UPDATE Overrides existing resource GET SELECT Fetches a resource. The resource is never changed via a GET request DELETE DELETE Deletes a resource
  • 10. HTTP REST Request: HTTP REST API Request GET https://www.myhost.com/api/v1/user/1/cities Read, All the cities for user whose id is 1 GET /user/1/cities http/1.1 host: https://www.myhost.com/api/v1 Content-Type: application/json Accept-Language: us-en state_id: 2
  • 11. HTTP REST Response: HTTP REST API Response HTTP/1.1 200 OK (285ms) Date: Fri, 21 Apr 2017 10:27:20 GMT Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/7.0.16 X-Powered-By: PHP/7.0.16 Content-Length: 109 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/json; charset=UTF-8 {"status":"success","message":"City List","data":[{"city_name":"Visakhapatnam"},{"city_name":"Vijayawada"}]}
  • 12. HTTP Response Status Code: 1xx Informational Codes 2xx Successful Codes 3xx Redirection Codes 4xx Client Error Code 5xx Server Error Codes List at here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
  • 13. Points to be noted For REST APIs
  • 14. Use Nouns but no verbs in path/URI: Purpose Method Incorrect Correct Retrieves a list of users GET /getAllCars /users Create a new user POST /createUser /users Delete a user DELETE /deleteUser /users/10 Get balance of user GET /getUserBalance /users/11/balance
  • 15. Use plural nouns: Do not mix up singular and plural nouns. Keep it simple and use only plural nouns for all resources. /cars instead of /car /users instead of /user /products instead of /product /settings instead of /setting
  • 16. GET method should not alter the state: Use PUT, POST and DELETE methods instead of the GET method to alter the state. Do not use GET method or Query parameters for state changes: GET /users/711?activate or GET /users/711/activate
  • 17. Use sub-resources for relation: If a resource is related to another resource use subresources GET /cars/711/drivers/ (Returns a list of drivers for car 711) GET /cars/711/drivers/4 (Returns driver #4 for car 711)
  • 18. Use HTTP headers for serialization formats: Both, client and server need to know which format is used for the communication. The format has to be specified in the HTTP-Header. Content-Type defines the request format. Accept defines a list of acceptable response formats.
  • 19. Versioning is important: Make the API Version mandatory and do not release an unversioned API. Use a simple ordinal number and avoid dot notation such as 2.5 We are using the url for the API versioning starting with the letter “v” /blog/api/v1
  • 20. Handle Errors with HTTP Status code: 200 OK (Everything is working) 403 Forbidden (The server understood the request, but is refusing it or the access is not allowed) 201 OK (New resource has been created) 404 Not found (There is no resource behind the URI) 204 OK (Resource successfully deleted) 405 Method not allowed 400 Bad Request (The request was invalid or cannot be served. The exact error should be explained in the error payload. E.g. „The JSON is not valid“) 408 Request timeout 401 Unauthorized (The request requires an user authentication) 500 Internal server error
  • 21. Filtering: Use a unique query parameter for all fields or a query language for filtering. GET /cars?color=red (Returns a list of red cars) GET /users?name=tom (Returns a list of users whose name matches tom)
  • 22. Sorting: Allow ascending and descending sorting over multiple fields. GET /cars?sort=-manufacturer,+model This returns a list of cars sorted by descending manufacturers and ascending models)
  • 23. Paging: Use limit and offset. It is flexible for the user and common in leading databases. The default should be limit=20 and offset=0 GET /cars?offset=10&limit=5
  • 24. Aliases for common queries: To make the API experience more pleasant for the average consumer, consider packaging up sets of conditions into easily accessible RESTful paths. For example consider following use case: POST /users (User Register: Creates a new user) POST /users/login (User Login: Creates auth token for user authentication)
  • 25. Want to develop REST APIs easily??? Checkout Slim - A microframework for php. Documentation: https://www.slimframework.com/docs/
  • 26. Thanks for your Time & Patience! Any Question?