SlideShare a Scribd company logo
1 of 20
Download to read offline
RESTFul Design
Principles
Geison Goes
REST (Representational State Transfer) is an architectural style,
and an approach to communications that is often used in the
development of Web services and nowadays with Mobile world
and Internet of Things.
What is REST
RESTFul Design Principles
The primary design principle when crafting your API
should be to maximize developer productivity and
success.
Main GOAL
RESTFul Design Principles
Nouns are good; verbs are bad!
Keep your base URL simple and intuitive, use HTTP Verbs:
Principle number 1 - CRUD Actions
RESTFul Design Principles
HTTP Verb Path - GOOD Path - BAD HTTP Status Response
GET /photos /getAllPhotos 200 JSON with a list of all photos
GET /photos/:id /getPhoto/:id 200 JSON with a photo
POST /photos /createPhoto 201 JSON with a new photo
PATCH/PUT /photos/:id /updatePhoto 200 JSON with updated photo
DELETE /photos /deleteAllPhotos 200 JSON with deleted photos
DELETE /photos/:id /deletePhoto 200 JSON with deleted photo
Just 2 entry points to perform all CRUD actions
Principle number 1 - CRUD Actions
RESTFul Design Principles
RESOURCE POST GET PUT DELETE
/photos Create a new photo Return all photos Update all photos Delete all photos
/photos/1234 405 Method not allowed Return photo Update photo or
return 400 not found
Delete photo or
return 400 not found
Keeps the CRUD actions just one level deep:
Principle number 2 - Associations
RESTFul Design Principles
RESOURCE POST GET PUT DELETE
/users/:id/photos Create a new photo for
this user
Return all photos
of this user
Update all photos of
this user
Delete all photos
/users/:id/photos/1234 405 Method not allowed Return this photo
of this user
Update this photo of
this user or return
400 not found
Delete this photo of
this user or return
400 not found
In order to facilitate the developers work, always provides
Eager and Lazy ways to get resources that have
associations.
Principle number 3 - Eager or Lazy Loading
RESTFul Design Principles
Lazy loading - get user photos:
Principle number 3 - Eager or Lazy Loading
RESTFul Design Principles
RESOURCE POST GET PUT DELETE
/users Create a new photo Return all photos Update all photos Delete all photos
/users/1234 405 Method not allowed Return photo Update photo or
return 400 not found
Delete photo or
return 400 not found
Step 1:
Step 2:
RESOURCE POST GET PUT DELETE
/users/1234/photos Create a new photo
for this user
Return all photos
of this user
Update all photos of
this user
Delete all photos
/users/1234/photos/1234 405 Method not
allowed
Return this photo
of this user
Update this photo of
this user or return
400 not found
Delete this photo of
this user or return
400 not found
Eager loading - get user photos:
Principle number 3 - Eager or Lazy Loading
RESTFul Design Principles
RESOURCE POST GET PUT DELETE
/users?include=photos 405 Method
not allowed
Return all Users
with his photos
Update all Users
and his photos
Delete all Users
and their photos
/users/:id/?include=photos 405 Method
not allowed
Return this User
with his photos
Update this User
with his photos
Delete this User
and his photos
/users?include=photos&comments 405 Method
not allowed
Return this User
with his photos and
comments
Update this User
with his photos
and comments
Delete this User
with his photos
and comments
Some times it is not necessary get all information about
resources, in fact is necessary just some fields or a specific
characteristic and also sorting and paginate the results.
Principle number 4 - Filters
RESTFul Design Principles
GET /users?fields=name,email,phone
GET /photos?fields=title,size,state
Principle number 4 - Filters
RESTFul Design Principles
Fields
GET /user?sort=age,name
fields with - sign will be sorting in descending order
GET /user?sort=age,-name
Principle number 4 - Filters
RESTFul Design Principles
Sorting
GET /photos?limit=25&offset=50
Principle number 4 - Filters
RESTFul Design Principles
Paginating
To have a complete REST API it was necessary implement
two kind of searches:
1. Global Search
GET /search?resources=photos&title=fog&size=small
GET /search?resources=photos,images&size=small
2. Scoped Search
GET /photos?title=fog&size=small
GET /users/1234/photos?title=fog&size=small
Principle number 5 - Search
RESTFul Design Principles
In order to provide to developers the necessary information
when erros happens, returns error messages in the
response body
HTTP Status Code: 401
{"code" : 401, "message": "Authentication Required"}
Principle number 6 - Error Handling
RESTFul Design Principles
Versioning the API is a way to keep backward compatibility,
to implement it, just provide the API version in the URI
GET /v1.0/users
Principle number 7 - Versioning
RESTFul Design Principles
Some times it is necessary to create APIs that are
responsible to perform actions instead of return resources,
these were the unique cases where verbs are allowed
GET /convert?from=EUR&to=CNY&amount=100
GET /calculate?operation=sum&val1=8&val2=4
Principle number 8 - Exceptions
RESTFul Design Principles
When resources could not be public, a authentication
mechanism becomes necessary and in this case there is
no question that the best approach to implement it is
OAuth2.
To get more information about OAuth2 and how to
implement it follow this links below:
- http://en.wikipedia.org/wiki/OAuth
- http://oauth.net/2/
Principle number 9 - Authentication
RESTFul Design Principles
Principle number 9 - Authentication
RESTFul Design Principles
RESTFul Design Principles
● Email:
○ geisonfgf@gmail.com
● Skype
○ geisonfgf
● Facebook
○ http://www.facebook.com/geisonfgf
● Twitter
○ http://www.twitter.com/geisonfgf
Contact me

More Related Content

Viewers also liked

Wso2 con byod-shan-ppt
Wso2 con byod-shan-pptWso2 con byod-shan-ppt
Wso2 con byod-shan-ppt
WSO2
 
humanities principle of visual art
humanities principle of visual arthumanities principle of visual art
humanities principle of visual art
ayacastillo25
 
Islamic architecture report
Islamic architecture reportIslamic architecture report
Islamic architecture report
Icah Quinto
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
Bo-Yi Wu
 

Viewers also liked (20)

PFBE's Architectural Principles. Part14/16: Sustainability and Tradition
PFBE's Architectural Principles. Part14/16: Sustainability and TraditionPFBE's Architectural Principles. Part14/16: Sustainability and Tradition
PFBE's Architectural Principles. Part14/16: Sustainability and Tradition
 
Wso2 con byod-shan-ppt
Wso2 con byod-shan-pptWso2 con byod-shan-ppt
Wso2 con byod-shan-ppt
 
Architectural Design 1 Lectures by Dr. Yasser Mahgoub - Lecture 10 Aesthetics
Architectural Design 1 Lectures by Dr. Yasser Mahgoub - Lecture 10 AestheticsArchitectural Design 1 Lectures by Dr. Yasser Mahgoub - Lecture 10 Aesthetics
Architectural Design 1 Lectures by Dr. Yasser Mahgoub - Lecture 10 Aesthetics
 
Cross Platform Mobile Apps with APIs from Qcon San Francisco
Cross Platform Mobile Apps with APIs from Qcon San FranciscoCross Platform Mobile Apps with APIs from Qcon San Francisco
Cross Platform Mobile Apps with APIs from Qcon San Francisco
 
RESTful API development with Symfony2
RESTful API development with Symfony2RESTful API development with Symfony2
RESTful API development with Symfony2
 
Principles
PrinciplesPrinciples
Principles
 
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
 
humanities principle of visual art
humanities principle of visual arthumanities principle of visual art
humanities principle of visual art
 
Islamic architecture report
Islamic architecture reportIslamic architecture report
Islamic architecture report
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015
 
DataPower Restful API Security
DataPower Restful API SecurityDataPower Restful API Security
DataPower Restful API Security
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Building REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudBuilding REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring Cloud
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business6 Reasons Why APIs Are Reshaping Your Business
6 Reasons Why APIs Are Reshaping Your Business
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
REST, RESTful API
REST, RESTful APIREST, RESTful API
REST, RESTful API
 
RESTful API and ASP.NET
RESTful API and ASP.NETRESTful API and ASP.NET
RESTful API and ASP.NET
 
REST and Microservices
REST and MicroservicesREST and Microservices
REST and Microservices
 

Similar to Restful design principles

Timeline SoMa WADE
Timeline SoMa WADETimeline SoMa WADE
Timeline SoMa WADE
Irnuk
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
goldoraf
 
Designing Res Tful Rails Applications
Designing Res Tful Rails ApplicationsDesigning Res Tful Rails Applications
Designing Res Tful Rails Applications
ConSanFrancisco123
 
Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
henri_makembe
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Nguyen Duc Phu
 

Similar to Restful design principles (20)

Timeline SoMa WADE
Timeline SoMa WADETimeline SoMa WADE
Timeline SoMa WADE
 
EdTechJoker Spring 2020 - Lecture 8 Drupal again
EdTechJoker Spring 2020 - Lecture 8 Drupal againEdTechJoker Spring 2020 - Lecture 8 Drupal again
EdTechJoker Spring 2020 - Lecture 8 Drupal again
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
RAML - The architecture
RAML  - The architectureRAML  - The architecture
RAML - The architecture
 
Services web RESTful
Services web RESTfulServices web RESTful
Services web RESTful
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOP
 
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...
 
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
 
Designing Res Tful Rails Applications
Designing Res Tful Rails ApplicationsDesigning Res Tful Rails Applications
Designing Res Tful Rails Applications
 
sh404SEF goes Social talk at JoomlaDay Midwest 2011
sh404SEF goes Social talk at JoomlaDay Midwest 2011sh404SEF goes Social talk at JoomlaDay Midwest 2011
sh404SEF goes Social talk at JoomlaDay Midwest 2011
 
Architect's Guide to Building an API Program
Architect's Guide to Building an API ProgramArchitect's Guide to Building an API Program
Architect's Guide to Building an API Program
 
Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
 
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
Hanoi php day 2008 - 05. nguyen hai nhat huy - building-restful-web-service-w...
 
Web API Design
Web API DesignWeb API Design
Web API Design
 
Web API Design: Crafting Interfaces that Developers Love
Web API Design:  Crafting Interfaces that Developers LoveWeb API Design:  Crafting Interfaces that Developers Love
Web API Design: Crafting Interfaces that Developers Love
 
VIZ Embedded Metadata Workshop
VIZ Embedded Metadata WorkshopVIZ Embedded Metadata Workshop
VIZ Embedded Metadata Workshop
 
Rest applied
Rest appliedRest applied
Rest applied
 
Google Photos GTM.pdf.pdf
Google Photos GTM.pdf.pdfGoogle Photos GTM.pdf.pdf
Google Photos GTM.pdf.pdf
 
Day02 a pi.
Day02   a pi.Day02   a pi.
Day02 a pi.
 

More from Geison Goes

More from Geison Goes (11)

Kotlin multiplataforma
Kotlin multiplataformaKotlin multiplataforma
Kotlin multiplataforma
 
Why companies like Google, Alibaba and UOL choose Flutter
Why companies like Google, Alibaba and UOL choose FlutterWhy companies like Google, Alibaba and UOL choose Flutter
Why companies like Google, Alibaba and UOL choose Flutter
 
Functional Swift
Functional SwiftFunctional Swift
Functional Swift
 
Functional Go
Functional GoFunctional Go
Functional Go
 
Functional go
Functional goFunctional go
Functional go
 
Cucumber - use it to describe user stories and acceptance criterias
Cucumber - use it to describe user stories and acceptance criteriasCucumber - use it to describe user stories and acceptance criterias
Cucumber - use it to describe user stories and acceptance criterias
 
Gil - the responsible to unable paralellism
Gil - the responsible to unable paralellismGil - the responsible to unable paralellism
Gil - the responsible to unable paralellism
 
An introduction to the ruby ecosystem
An introduction to the ruby ecosystemAn introduction to the ruby ecosystem
An introduction to the ruby ecosystem
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Python Flavors
Python FlavorsPython Flavors
Python Flavors
 
Ruby Functional Programming
Ruby Functional ProgrammingRuby Functional Programming
Ruby Functional Programming
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
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...
 
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...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Restful design principles

  • 2. REST (Representational State Transfer) is an architectural style, and an approach to communications that is often used in the development of Web services and nowadays with Mobile world and Internet of Things. What is REST RESTFul Design Principles
  • 3. The primary design principle when crafting your API should be to maximize developer productivity and success. Main GOAL RESTFul Design Principles
  • 4. Nouns are good; verbs are bad! Keep your base URL simple and intuitive, use HTTP Verbs: Principle number 1 - CRUD Actions RESTFul Design Principles HTTP Verb Path - GOOD Path - BAD HTTP Status Response GET /photos /getAllPhotos 200 JSON with a list of all photos GET /photos/:id /getPhoto/:id 200 JSON with a photo POST /photos /createPhoto 201 JSON with a new photo PATCH/PUT /photos/:id /updatePhoto 200 JSON with updated photo DELETE /photos /deleteAllPhotos 200 JSON with deleted photos DELETE /photos/:id /deletePhoto 200 JSON with deleted photo
  • 5. Just 2 entry points to perform all CRUD actions Principle number 1 - CRUD Actions RESTFul Design Principles RESOURCE POST GET PUT DELETE /photos Create a new photo Return all photos Update all photos Delete all photos /photos/1234 405 Method not allowed Return photo Update photo or return 400 not found Delete photo or return 400 not found
  • 6. Keeps the CRUD actions just one level deep: Principle number 2 - Associations RESTFul Design Principles RESOURCE POST GET PUT DELETE /users/:id/photos Create a new photo for this user Return all photos of this user Update all photos of this user Delete all photos /users/:id/photos/1234 405 Method not allowed Return this photo of this user Update this photo of this user or return 400 not found Delete this photo of this user or return 400 not found
  • 7. In order to facilitate the developers work, always provides Eager and Lazy ways to get resources that have associations. Principle number 3 - Eager or Lazy Loading RESTFul Design Principles
  • 8. Lazy loading - get user photos: Principle number 3 - Eager or Lazy Loading RESTFul Design Principles RESOURCE POST GET PUT DELETE /users Create a new photo Return all photos Update all photos Delete all photos /users/1234 405 Method not allowed Return photo Update photo or return 400 not found Delete photo or return 400 not found Step 1: Step 2: RESOURCE POST GET PUT DELETE /users/1234/photos Create a new photo for this user Return all photos of this user Update all photos of this user Delete all photos /users/1234/photos/1234 405 Method not allowed Return this photo of this user Update this photo of this user or return 400 not found Delete this photo of this user or return 400 not found
  • 9. Eager loading - get user photos: Principle number 3 - Eager or Lazy Loading RESTFul Design Principles RESOURCE POST GET PUT DELETE /users?include=photos 405 Method not allowed Return all Users with his photos Update all Users and his photos Delete all Users and their photos /users/:id/?include=photos 405 Method not allowed Return this User with his photos Update this User with his photos Delete this User and his photos /users?include=photos&comments 405 Method not allowed Return this User with his photos and comments Update this User with his photos and comments Delete this User with his photos and comments
  • 10. Some times it is not necessary get all information about resources, in fact is necessary just some fields or a specific characteristic and also sorting and paginate the results. Principle number 4 - Filters RESTFul Design Principles
  • 11. GET /users?fields=name,email,phone GET /photos?fields=title,size,state Principle number 4 - Filters RESTFul Design Principles Fields
  • 12. GET /user?sort=age,name fields with - sign will be sorting in descending order GET /user?sort=age,-name Principle number 4 - Filters RESTFul Design Principles Sorting
  • 13. GET /photos?limit=25&offset=50 Principle number 4 - Filters RESTFul Design Principles Paginating
  • 14. To have a complete REST API it was necessary implement two kind of searches: 1. Global Search GET /search?resources=photos&title=fog&size=small GET /search?resources=photos,images&size=small 2. Scoped Search GET /photos?title=fog&size=small GET /users/1234/photos?title=fog&size=small Principle number 5 - Search RESTFul Design Principles
  • 15. In order to provide to developers the necessary information when erros happens, returns error messages in the response body HTTP Status Code: 401 {"code" : 401, "message": "Authentication Required"} Principle number 6 - Error Handling RESTFul Design Principles
  • 16. Versioning the API is a way to keep backward compatibility, to implement it, just provide the API version in the URI GET /v1.0/users Principle number 7 - Versioning RESTFul Design Principles
  • 17. Some times it is necessary to create APIs that are responsible to perform actions instead of return resources, these were the unique cases where verbs are allowed GET /convert?from=EUR&to=CNY&amount=100 GET /calculate?operation=sum&val1=8&val2=4 Principle number 8 - Exceptions RESTFul Design Principles
  • 18. When resources could not be public, a authentication mechanism becomes necessary and in this case there is no question that the best approach to implement it is OAuth2. To get more information about OAuth2 and how to implement it follow this links below: - http://en.wikipedia.org/wiki/OAuth - http://oauth.net/2/ Principle number 9 - Authentication RESTFul Design Principles
  • 19. Principle number 9 - Authentication RESTFul Design Principles
  • 20. RESTFul Design Principles ● Email: ○ geisonfgf@gmail.com ● Skype ○ geisonfgf ● Facebook ○ http://www.facebook.com/geisonfgf ● Twitter ○ http://www.twitter.com/geisonfgf Contact me