SlideShare a Scribd company logo
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

PPTX
Hands on Gradle
PDF
Modern javascript
PDF
RubyConf China 2015 - Rails off assets pipeline
PPTX
Saving Time By Testing With Jest
PDF
Hello world - intro to node js
PDF
Thinking in React
PPTX
Agile sites @ telmore
PDF
Masterin Large Scale Java Script Applications
Hands on Gradle
Modern javascript
RubyConf China 2015 - Rails off assets pipeline
Saving Time By Testing With Jest
Hello world - intro to node js
Thinking in React
Agile sites @ telmore
Masterin Large Scale Java Script Applications

What's hot (20)

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

Similar to Webservices: The RESTful Approach (20)

PDF
Modern REST API design principles and rules.pdf
PDF
What is REST?
PDF
Modern REST API design principles and rules.pdf
PDF
REST API Recommendations
PPTX
Api Design
KEY
Designing a RESTful web service
PDF
Web API Design: Crafting Interfaces that Developers Love
PDF
Web API Design
PPSX
Restful web services rule financial
PPTX
Rest APIs Training
PPTX
A Deep Dive into RESTful API Design Part 2
PPTX
REST Methodologies
PDF
[GeekTalk#2] Takaaki Mizuno - Api Url Design
PDF
Restful web-services
PPTX
Building Software Backend (Web API)
PDF
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
PDF
Great APIs - Future of Your Progress App
PDF
Web REST APIs Design Principles
PPTX
Http and REST APIs.
PPTX
Best Practices in Api Design
Modern REST API design principles and rules.pdf
What is REST?
Modern REST API design principles and rules.pdf
REST API Recommendations
Api Design
Designing a RESTful web service
Web API Design: Crafting Interfaces that Developers Love
Web API Design
Restful web services rule financial
Rest APIs Training
A Deep Dive into RESTful API Design Part 2
REST Methodologies
[GeekTalk#2] Takaaki Mizuno - Api Url Design
Restful web-services
Building Software Backend (Web API)
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
Great APIs - Future of Your Progress App
Web REST APIs Design Principles
Http and REST APIs.
Best Practices in Api Design
Ad

More from Mushfekur Rahman (6)

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

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Introduction to Artificial Intelligence
PPTX
ai tools demonstartion for schools and inter college
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
PTS Company Brochure 2025 (1).pdf.......
System and Network Administration Chapter 2
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
VVF-Customer-Presentation2025-Ver1.9.pptx
Materi_Pemrograman_Komputer-Looping.pptx
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction to Artificial Intelligence
ai tools demonstartion for schools and inter college
ManageIQ - Sprint 268 Review - Slide Deck
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How Creative Agencies Leverage Project Management Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PTS Company Brochure 2025 (1).pdf.......

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