SlideShare a Scribd company logo
1 of 21
Webservices: The RESTful
Approach
Mushfekur Rahman
Associate Software Engineer
Therap BD Ltd.
Outline
• Intro to Webservice
• What is REST
• API Designing Good Practices
• A Simple RESTful Webservice using Spring
Webservice
• Software components that interact with one another via standard
protocols (i.e. HTTP)
• Applications running on webservers that exposes
1. Functionality
2. Data
• Example
• Those ‘Powered by Google’ search boxes in websites (functionality)
• Facebook Graph API (data)
• Webservices ≈ Web APIs
Webservice (cont.)
• The whole scene
• Web application
• APIs
• HTTP
• Clients
Try to visualize
Browser
CLI (wget, curl)
Web Apps
Mobile (iOS, Android)
Network Web Application
A
P
I
Webservice (cont.)
• Implementation Architectures
• SOAP
• Simple Object Access Protocol
• Old school
• REST
• REpresentational State Transfer
• This is how ‘cool kids’ do it nowadays!
REST
• What is it?
• An architectural style to implement web APIs
• Introduced in 2000 by Roy T. Fielding
• His PhD thesis (Ch. 5)
• http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
REST (cont.)
• What it’s not
• A framework
• A technology
• A standards specification
Yep, remember it’s just an architectural STYLE
REST (cont.)
• Key properties
• Statelessness
• State resides on client-end
• Improves portability, scalability
• Resource oriented
• Everything that can be named is a resource
• Every resource is mapped with an unique URL (so be careful when choosing one)
• Uniform interface
• Interface is same for any operation (GET, POST, PUT, DELETE)
REST (cont.)
• URL as resource locators
• HTTP methods as verbs
• GET
• POST
• PUT
• DELETE
• Media Types
• XML
• application/xml
• JSON (JavaScript Object Notation)
• application/json
API Designing Good Practices
• Let’s design some APIs for http://www.imdb.com/
• Our resources
• Movies 
• A possible ‘subset’ of URLs can be
/getMovie/{id}
/newMovie
/updateMovie/{id}
/deleteMovie/{id}
/getAllMovies
/updateAllMovies
/deleteAllMovies
/updateMovie/{id}/actors
/getAllMoviesReleasedInYear/{year}
/getAllMoviesActedBy/{actorName}
/getAllMoviesDirectedBy/{dirName}
/updateAllMoviesReleasedInYear/{year}
/updateAllMoviesActedBy/{actorName}
/updateAllMoviesDirectedBy/{dirName}
/deleteAllMoviesReleasedInYear/{year}
/deleteAllMoviesActedBy/{actorName}
/deleteAllMoviesDirectedBy/{dirName}
We are really on a slippery-slope!
API Designing Good Practices (cont.)
• Two base URLs per resource
1. One for collections
• /movies
2. Another for a specific element
• /movies/123
API Designing Good Practices (cont.)
• Verbs or nouns?
• Nouns are good, verbs are bad
• Singular or plural?
• Plurals are better
• Forsquare /checkins
• GroupOn /deals
• Abstract or concrete
• Concretes are more specific (/movies better than /things)
API Designing Good Practices (cont.)
Resource GET POST PUT DELETE
/movies get all movies create a new movie bulk update movies delete all movies
/movies/123 get the movie with
id 123
error If exists update,
otherwise error
delete it
API Designing Good Practices (cont.)
• What about association?
• Maintain hierarchy
• /movies/123/actors
• What about complex variations?
• Use the good old ‘?’ (URL parameters)
• /movies?releasedIn=2004&actedBy=Natalie%20Portman
• Use CamelCasing for URL parameter naming
• Should not use GET for any operation that causes state change in server
side
• No create/update/delete operation using GET
API Designing Good Practices (cont.)
• The world we live in is not so perfect
• There are errors (and exceptions)
• How should we act on such times?
• Handle ‘em
• Why it’s important
• Ensures robustness
• Easier for developers (API users) to understand what’s going wrong
API Designing Good Practices (cont.)
• How should we do it?
• HTTP Status Codes
• 200 OK
• 404 Not Found
• There are about 70 status codes so how many we should use?
• Google GData uses 10
• 200 201 304 400 401 403 404 409 410 500
• Netflix uses 9
• 200 201 304 400 401 403 404 412 500
API Designing Good Practices (cont.)
• What are the very basic possible situations?
• Everything went smooth (200 - OK)
• You messed up (400 - Bad Request)
• Server messed up (500 - Internal Server Error)
• Ultimately it all boils down to 3
• Start with these 3
• Don’t go over 8
Let’s Code!
Components
Serialization/Deserialization
Jackson
ExceptionHandlerController
MovieController
MovieService
References
• apigee web API design guide
http://apigee.com/about/resources/ebooks/web-api-design
• Spring REST tutorial
http://spring.io/understanding/REST

More Related Content

What's hot

Building next gen android library with gradle
Building next gen android library with gradleBuilding next gen android library with gradle
Building next gen android library with gradle
Anton Rutkevich
 

What's hot (20)

TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)TypeScript and Angular2 (Love at first sight)
TypeScript and Angular2 (Love at first sight)
 
Agile sites2
Agile sites2Agile sites2
Agile sites2
 
Ci of js and apex using jasmine, phantom js and drone io df14
Ci of js and apex using jasmine, phantom js and drone io   df14Ci of js and apex using jasmine, phantom js and drone io   df14
Ci of js and apex using jasmine, phantom js and drone io df14
 
ASP.NET MVC
ASP.NET MVCASP.NET MVC
ASP.NET MVC
 
UPenn on Rails intro
UPenn on Rails introUPenn on Rails intro
UPenn on Rails intro
 
Building next gen android library with gradle
Building next gen android library with gradleBuilding next gen android library with gradle
Building next gen android library with gradle
 
Migrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to GoMigrate PHP E-Commerce Site to Go
Migrate PHP E-Commerce Site to Go
 
Being With Rails App For 3 Years
Being With Rails App For 3 YearsBeing With Rails App For 3 Years
Being With Rails App For 3 Years
 
React Native
React NativeReact Native
React Native
 
Jasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScriptJasmine - A BDD test framework for JavaScript
Jasmine - A BDD test framework for JavaScript
 
SGCE 2015 REST APIs
SGCE 2015 REST APIsSGCE 2015 REST APIs
SGCE 2015 REST APIs
 
Next generation frontend tooling
Next generation frontend toolingNext generation frontend tooling
Next generation frontend tooling
 
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
Michael North "Ember.js 2 - Future-friendly ambitious apps, that scale!"
 
Android talks #08 decompiling android applications
Android talks #08   decompiling android applicationsAndroid talks #08   decompiling android applications
Android talks #08 decompiling android applications
 
React native: building native iOS apps with javascript
React native: building native iOS apps with javascriptReact native: building native iOS apps with javascript
React native: building native iOS apps with javascript
 
Craft Beer & Clojure
Craft Beer & ClojureCraft Beer & Clojure
Craft Beer & Clojure
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
Design for scale
Design for scaleDesign for scale
Design for scale
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Rapid development with Rails
Rapid development with RailsRapid development with Rails
Rapid development with Rails
 

Similar to Webservices: The RESTful Approach

Transitioning Groupon to Node.js - EmpireJS 2014
Transitioning Groupon to Node.js - EmpireJS 2014Transitioning Groupon to Node.js - EmpireJS 2014
Transitioning Groupon to Node.js - EmpireJS 2014
Sean McCullough
 

Similar to Webservices: The RESTful Approach (20)

Api fundamentals
Api fundamentalsApi fundamentals
Api fundamentals
 
Introduction to Google APIs
Introduction to Google APIsIntroduction to Google APIs
Introduction to Google APIs
 
Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017
 
Creating a Responsive Website From Scratch
Creating a Responsive Website From ScratchCreating a Responsive Website From Scratch
Creating a Responsive Website From Scratch
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 
Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.js
 
RESTful web services with Groovy on Grails by Vugar Suleymanov
RESTful web services with Groovy on Grails by Vugar SuleymanovRESTful web services with Groovy on Grails by Vugar Suleymanov
RESTful web services with Groovy on Grails by Vugar Suleymanov
 
How to Build Single Page HTML5 Apps that Scale
How to Build Single Page HTML5 Apps that ScaleHow to Build Single Page HTML5 Apps that Scale
How to Build Single Page HTML5 Apps that Scale
 
Rhodes
RhodesRhodes
Rhodes
 
Embracing HTTP in the era of API’s
Embracing HTTP in the era of API’sEmbracing HTTP in the era of API’s
Embracing HTTP in the era of API’s
 
The Characteristics of a Successful SPA
The Characteristics of a Successful SPAThe Characteristics of a Successful SPA
The Characteristics of a Successful SPA
 
Transitioning Groupon to Node.js - EmpireJS 2014
Transitioning Groupon to Node.js - EmpireJS 2014Transitioning Groupon to Node.js - EmpireJS 2014
Transitioning Groupon to Node.js - EmpireJS 2014
 
Structured Functional Automated Web Service Testing
Structured Functional Automated Web Service TestingStructured Functional Automated Web Service Testing
Structured Functional Automated Web Service Testing
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Magento Meetup New Delhi- API
Magento Meetup New Delhi- APIMagento Meetup New Delhi- API
Magento Meetup New Delhi- API
 
Lessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxLessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptx
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 
Api crash
Api crashApi crash
Api crash
 

More from Mushfekur Rahman (6)

An Automatic Method for Red-eye Detection and Correction in Digital Images
An Automatic Method for Red-eye Detection and Correction in Digital ImagesAn Automatic Method for Red-eye Detection and Correction in Digital Images
An Automatic Method for Red-eye Detection and Correction in Digital Images
 
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMCDiagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
 
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and KibanaBuilding a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana
 
Http Basics
Http BasicsHttp Basics
Http Basics
 
Distributed Transaction Management in Spring & JEE
Distributed Transaction Management in Spring & JEEDistributed Transaction Management in Spring & JEE
Distributed Transaction Management in Spring & JEE
 
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
 

Recently uploaded

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

Recently uploaded (20)

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
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...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 

Webservices: The RESTful Approach

  • 1. Webservices: The RESTful Approach Mushfekur Rahman Associate Software Engineer Therap BD Ltd.
  • 2. Outline • Intro to Webservice • What is REST • API Designing Good Practices • A Simple RESTful Webservice using Spring
  • 3. Webservice • Software components that interact with one another via standard protocols (i.e. HTTP) • Applications running on webservers that exposes 1. Functionality 2. Data • Example • Those ‘Powered by Google’ search boxes in websites (functionality) • Facebook Graph API (data) • Webservices ≈ Web APIs
  • 4. Webservice (cont.) • The whole scene • Web application • APIs • HTTP • Clients
  • 5. Try to visualize Browser CLI (wget, curl) Web Apps Mobile (iOS, Android) Network Web Application A P I
  • 6. Webservice (cont.) • Implementation Architectures • SOAP • Simple Object Access Protocol • Old school • REST • REpresentational State Transfer • This is how ‘cool kids’ do it nowadays!
  • 7. REST • What is it? • An architectural style to implement web APIs • Introduced in 2000 by Roy T. Fielding • His PhD thesis (Ch. 5) • http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm
  • 8. REST (cont.) • What it’s not • A framework • A technology • A standards specification Yep, remember it’s just an architectural STYLE
  • 9. REST (cont.) • Key properties • Statelessness • State resides on client-end • Improves portability, scalability • Resource oriented • Everything that can be named is a resource • Every resource is mapped with an unique URL (so be careful when choosing one) • Uniform interface • Interface is same for any operation (GET, POST, PUT, DELETE)
  • 10. REST (cont.) • URL as resource locators • HTTP methods as verbs • GET • POST • PUT • DELETE • Media Types • XML • application/xml • JSON (JavaScript Object Notation) • application/json
  • 11. API Designing Good Practices • Let’s design some APIs for http://www.imdb.com/ • Our resources • Movies  • A possible ‘subset’ of URLs can be /getMovie/{id} /newMovie /updateMovie/{id} /deleteMovie/{id} /getAllMovies /updateAllMovies /deleteAllMovies /updateMovie/{id}/actors /getAllMoviesReleasedInYear/{year} /getAllMoviesActedBy/{actorName} /getAllMoviesDirectedBy/{dirName} /updateAllMoviesReleasedInYear/{year} /updateAllMoviesActedBy/{actorName} /updateAllMoviesDirectedBy/{dirName} /deleteAllMoviesReleasedInYear/{year} /deleteAllMoviesActedBy/{actorName} /deleteAllMoviesDirectedBy/{dirName} We are really on a slippery-slope!
  • 12. API Designing Good Practices (cont.) • Two base URLs per resource 1. One for collections • /movies 2. Another for a specific element • /movies/123
  • 13. API Designing Good Practices (cont.) • Verbs or nouns? • Nouns are good, verbs are bad • Singular or plural? • Plurals are better • Forsquare /checkins • GroupOn /deals • Abstract or concrete • Concretes are more specific (/movies better than /things)
  • 14. API Designing Good Practices (cont.) Resource GET POST PUT DELETE /movies get all movies create a new movie bulk update movies delete all movies /movies/123 get the movie with id 123 error If exists update, otherwise error delete it
  • 15. API Designing Good Practices (cont.) • What about association? • Maintain hierarchy • /movies/123/actors • What about complex variations? • Use the good old ‘?’ (URL parameters) • /movies?releasedIn=2004&actedBy=Natalie%20Portman • Use CamelCasing for URL parameter naming • Should not use GET for any operation that causes state change in server side • No create/update/delete operation using GET
  • 16. API Designing Good Practices (cont.) • The world we live in is not so perfect • There are errors (and exceptions) • How should we act on such times? • Handle ‘em • Why it’s important • Ensures robustness • Easier for developers (API users) to understand what’s going wrong
  • 17. API Designing Good Practices (cont.) • How should we do it? • HTTP Status Codes • 200 OK • 404 Not Found • There are about 70 status codes so how many we should use? • Google GData uses 10 • 200 201 304 400 401 403 404 409 410 500 • Netflix uses 9 • 200 201 304 400 401 403 404 412 500
  • 18. API Designing Good Practices (cont.) • What are the very basic possible situations? • Everything went smooth (200 - OK) • You messed up (400 - Bad Request) • Server messed up (500 - Internal Server Error) • Ultimately it all boils down to 3 • Start with these 3 • Don’t go over 8
  • 21. References • apigee web API design guide http://apigee.com/about/resources/ebooks/web-api-design • Spring REST tutorial http://spring.io/understanding/REST