SlideShare a Scribd company logo
1 of 37
Designing REST services with
Spring MVC
Serhii Kartashov
December 2015
Softjourn
Internship
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
What is REST?
• REpresentational State Transfer
• Client/Server, Stateless, Uniform Interface
• Hightly-Cohesive, loosely coupled services
Uniform Interface
• Identification of resources
• Manipulation of resources
• Self-describing of resources
Representations of the resource over a
network
• URI - Uniform Resource Identifier
• URL - Uniform Resource Locator
• URN - Uniform Resource Name
HTTP's uniform interface
• URI's identify resources
/accounts/0
• HTTP verbs descried a limited set of
operations that can be used to manipulate a
resource
POST, GET, PUT, DELETE, ...
• Headers describes the messages
Content-Type: application/json
GET
• Retrieve Information
• Must be save and idempotent
• Get can be conditional or partial
If-Modified-Since
Range
DELETE
• Requests that a resource be removed
• The resource doesn't have to be removed
immediately
• Removal may be a long running task
DELETE /accounts/0
PUT
• Requests that the entity passed, be stored at
the URI
• Can be used to modify an existing one
PUT /accounts/0/creditcards/1
POST
• Requests that the resource at the URI do
something with the enclosed entity
Create, Modify
POST /accounts
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
Interaction Model
• List the current accounts in bank
• Create new account
• Create new credit card
• List the current credit cards of account
• Make transaction between two credit cards
• Lock credit card
• Delete account
List the current accounts in bank
• Need to return to us a collection that
represents
• Design doesn't have Account1, Account2,
Account..., just accounts
GET: /accounts
Response: [{"id":0,"name":"Mike"}, {...}, {...}]
Create new account
• Need to create new account in bank with
providing name of person
• Good practice is returning already created
account
POST: /accounts
json: {"name":"Matt"}
Response: {"id":2,"name":"Matt"}
Create new credit card
• That just a request for creation credit card
automatically
POST: /accounts/2/creditcards
json: {"pin":1111, "cardNumber":2,
"cardStatus":"ACTIVE", "remnant":0.0}
List the current credit cards of account
• Need to return to us a collection of all
available credit cards
GET: /accounts/2/creditcards
Response: [ {"pin":1111, "cardNumber":2,
"cardStatus":"ACTIVE", "remnant":0.0} ]
Make transaction between two credit
cards
• Transaction be running during some time
• Possible situation when you created just a
request for transaction and receive just info
when this will be precessed
POST: /accounts/2/creditcards
json: {"fromCreditCard": "1", "toCreditCard": "2",
"amount": "20"}
Transaction successfully processed
Lock Credit Card
• Changed status of credit card
PUT: /accounts/2/creditcards/2
{"pin":1111, "cardNumber":2,
"cardStatus":"LOCKED", "remnant":20.0}
Delete account
• No input required
• No output required
DELETE /accounts/2
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
Status codes
• Status codes indicates the results of the
server's attempt to satisfy the request
• Broadly divided into categories
– 1XX: Informational
– 2XX: Success
– 3XX: Redirection
– 4XX: Client Error
– 5XX: Server Error
Success Status Codes
• 200 OK
Everything worked
• 201 Created
The server has successfully created a new resource
Newly created resource’s location returned in the
Location header
• 202 Accepted
The server has accepted the request, but it is not yet
complete
A location to determine the request’s current status can
be returned in the Location header
Client Error Status Codes
• 400 Bad Request
Malformed syntax
Should not be repeated without modification
• 401 Unauthorized
Authentication is required
Includes a WWW-‐Authenticate header
• 403 Forbidden
Server has understood but refuses to honor the
request
Should not be repeated without modification
Client Error Status Codes
• 404 Not Found
The server cannot find a resource matching a URI
• 406 Not Acceptable
The server can only return response entities that do
not match the client’s Accept header
• 409 Conflict
The resource is in a state that is in conflict with the
request
Client should attempt to rectify the conflict and
then resubmit the request
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
Communication between client and
server
Content types are negotiated using headers:
• Client describes what it wants with the Accept
header
• Server (and client during POST and PUT)
describes what it is sending with Content-
Type header
Common Media Types
• Application
– JSON: application/json
– XML: application/xml
– PDF: application/pdf
• Text
– HTML: text/html
– PLAIN: text/plain
Addition Media Types
• Image
– JPEG: image/jpeg
• Audio
– MP4: audio/mp4
– WEBM: audio/webm
• Video
– MP4: video/mp4
– WEBM: video/webm
• Prefix vnd (vendor specific files)
– application/vnd.android.package-archive - for apk files
– application/vnd.ms-excel
Agenda
What is REST?
CRUD operations
Status codes
Media types
SpringMVC instruments
What other instruments Spring MVC
can provide?
• @RestController
Union of @Controller and @RequestBody
annotations
• @RequestBody
• @RequestMapping
value; method; consumes; produces
• @PathVariable
• @RequestParam
What other instruments Spring MVC
can provide?
• @RequestHeader
• @MatrixVariable
/owners/{ownerId}/pets/{petId}
GET /owners/42;q=11;r=12/pets/21;q=22;s=23
@MatrixVariable(pathVar="petId") Map<String, String>
petMatrixVars
<mvc:annotation-driven enable-matrix-
variables="true"/>
• @SessionAttributes
• @ModelAttribute
• @CookieValue
What more?
• Testing REST with MockMvc
• REST Client
• Caching
• Version handling
• Scaling: CDN (Content Delivery Network)
Useful links
• Tutorials
– http://www.restapitutorial.com/
• Video & Articles
– https://www.youtube.com/watch?v=5WXYw4J4QOU
– ETags: http://www.infoq.com/articles/etags
– Manage REST API versions:
http://stackoverflow.com/questions/20198275/how-to-manage-rest-api-
versioning-with-spring?answertab=votes#tab-
tophttp://stackoverflow.com/questions/20198275/how-to-manage-rest-api-
versioning-with-spring?answertab=votes#tab-top
– Steps towards the glory of REST:
http://martinfowler.com/articles/richardsonMaturityModel.html
• Examples from presentation: https://github.com/searhiy/REST-examples
• Instruments & Tools
– https://github.com/spring-projects/spring-data-rest
– http://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate
Designing REST services with Spring MVC

More Related Content

What's hot

ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsPawanMM
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service DesignLorna Mitchell
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTelliando dias
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptxvodqancr
 
Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5PawanMM
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6PawanMM
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generationEleonora Ciceri
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEreneechemel
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsPawanMM
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical ApproachMadhaiyan Muthu
 
REST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkREST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkChris Weldon
 
Hadoop introduction
Hadoop introductionHadoop introduction
Hadoop introductionDong Ngoc
 

What's hot (20)

Rest web services
Rest web servicesRest web services
Rest web services
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, Servlets
 
Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
 
Excellent rest using asp.net web api
Excellent rest using asp.net web apiExcellent rest using asp.net web api
Excellent rest using asp.net web api
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
 
Web service testing_final.pptx
Web service testing_final.pptxWeb service testing_final.pptx
Web service testing_final.pptx
 
Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5Session 29 - Servlets - Part 5
Session 29 - Servlets - Part 5
 
SOAP-based Web Services
SOAP-based Web ServicesSOAP-based Web Services
SOAP-based Web Services
 
Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6Session 30 - Servlets - Part 6
Session 30 - Servlets - Part 6
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLEREST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
 
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web AppsSession 31 - Session Management, Best Practices, Design Patterns in Web Apps
Session 31 - Session Management, Best Practices, Design Patterns in Web Apps
 
AJAX - An introduction
AJAX - An introductionAJAX - An introduction
AJAX - An introduction
 
Web services - A Practical Approach
Web services - A Practical ApproachWeb services - A Practical Approach
Web services - A Practical Approach
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Rest and Rails
Rest and RailsRest and Rails
Rest and Rails
 
REST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkREST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend Framework
 
HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
 
Hadoop introduction
Hadoop introductionHadoop introduction
Hadoop introduction
 

Viewers also liked

Design REST-ful Web Service
Design REST-ful Web ServiceDesign REST-ful Web Service
Design REST-ful Web ServiceKevingo Tsai
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Serhii Kartashov
 
RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)EMC
 

Viewers also liked (6)

Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
 
Design REST-ful Web Service
Design REST-ful Web ServiceDesign REST-ful Web Service
Design REST-ful Web Service
 
Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.Testing database content with DBUnit. My experience.
Testing database content with DBUnit. My experience.
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)RESTful SOA and the Spring Framework (EMCWorld 2011)
RESTful SOA and the Spring Framework (EMCWorld 2011)
 

Similar to Designing REST services with Spring MVC

Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServicesPrateek Tandon
 
.NET Core, ASP.NET Core Course, Session 19
 .NET Core, ASP.NET Core Course, Session 19 .NET Core, ASP.NET Core Course, Session 19
.NET Core, ASP.NET Core Course, Session 19aminmesbahi
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with ODataMahek Merchant
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Mads Toustrup-Lønne
 
Moulding your enterprise with ROA
Moulding your enterprise with ROAMoulding your enterprise with ROA
Moulding your enterprise with ROAshirok
 
SCWCD : Session management : CHAP : 6
SCWCD : Session management : CHAP : 6SCWCD : Session management : CHAP : 6
SCWCD : Session management : CHAP : 6Ben Abdallah Helmi
 
Research Topics in Machine Hypermedia
Research Topics in Machine HypermediaResearch Topics in Machine Hypermedia
Research Topics in Machine HypermediaMichael Koster
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaVladimir Tsukur
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API DesignOCTO Technology
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleMayank Sharma
 
REST APIs for the Internet of Things
REST APIs for the Internet of ThingsREST APIs for the Internet of Things
REST APIs for the Internet of ThingsMichael Koster
 
REST APIs for an Internet of Things
REST APIs for an Internet of ThingsREST APIs for an Internet of Things
REST APIs for an Internet of ThingsMichael Koster
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API RecommendationsJeelani Shaik
 
Rest webservice ppt
Rest webservice pptRest webservice ppt
Rest webservice pptsinhatanay
 

Similar to Designing REST services with Spring MVC (20)

Rest & RESTful WebServices
Rest & RESTful WebServicesRest & RESTful WebServices
Rest & RESTful WebServices
 
REST API Design
REST API DesignREST API Design
REST API Design
 
Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
 
.NET Core, ASP.NET Core Course, Session 19
 .NET Core, ASP.NET Core Course, Session 19 .NET Core, ASP.NET Core Course, Session 19
.NET Core, ASP.NET Core Course, Session 19
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with OData
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0
 
Moulding your enterprise with ROA
Moulding your enterprise with ROAMoulding your enterprise with ROA
Moulding your enterprise with ROA
 
SCWCD : Session management : CHAP : 6
SCWCD : Session management : CHAP : 6SCWCD : Session management : CHAP : 6
SCWCD : Session management : CHAP : 6
 
Research Topics in Machine Hypermedia
Research Topics in Machine HypermediaResearch Topics in Machine Hypermedia
Research Topics in Machine Hypermedia
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with HypermediaTogether Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
 
RefCard RESTful API Design
RefCard RESTful API DesignRefCard RESTful API Design
RefCard RESTful API Design
 
GSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 ModuleGSoC Mideterm-OAuth2 Module
GSoC Mideterm-OAuth2 Module
 
REST APIs for the Internet of Things
REST APIs for the Internet of ThingsREST APIs for the Internet of Things
REST APIs for the Internet of Things
 
REST APIs for an Internet of Things
REST APIs for an Internet of ThingsREST APIs for an Internet of Things
REST APIs for an Internet of Things
 
APITalkMeetupSharable
APITalkMeetupSharableAPITalkMeetupSharable
APITalkMeetupSharable
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Rest webservice ppt
Rest webservice pptRest webservice ppt
Rest webservice ppt
 

Recently uploaded

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 TechniquesVictorSzoltysek
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%+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
 
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 pastPapp Krisztián
 
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 AidPhilip Schwarz
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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 GoalsJhone kinadey
 
%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 Hararemasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
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...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 

Recently uploaded (20)

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
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
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
 
%+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...
 
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
 
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
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+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...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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
 
%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 Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
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...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Designing REST services with Spring MVC

  • 1. Designing REST services with Spring MVC Serhii Kartashov December 2015 Softjourn Internship
  • 2. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 3. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 4. What is REST? • REpresentational State Transfer • Client/Server, Stateless, Uniform Interface • Hightly-Cohesive, loosely coupled services
  • 5. Uniform Interface • Identification of resources • Manipulation of resources • Self-describing of resources
  • 6. Representations of the resource over a network • URI - Uniform Resource Identifier • URL - Uniform Resource Locator • URN - Uniform Resource Name
  • 7. HTTP's uniform interface • URI's identify resources /accounts/0 • HTTP verbs descried a limited set of operations that can be used to manipulate a resource POST, GET, PUT, DELETE, ... • Headers describes the messages Content-Type: application/json
  • 8. GET • Retrieve Information • Must be save and idempotent • Get can be conditional or partial If-Modified-Since Range
  • 9. DELETE • Requests that a resource be removed • The resource doesn't have to be removed immediately • Removal may be a long running task DELETE /accounts/0
  • 10. PUT • Requests that the entity passed, be stored at the URI • Can be used to modify an existing one PUT /accounts/0/creditcards/1
  • 11. POST • Requests that the resource at the URI do something with the enclosed entity Create, Modify POST /accounts
  • 12. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 13. Interaction Model • List the current accounts in bank • Create new account • Create new credit card • List the current credit cards of account • Make transaction between two credit cards • Lock credit card • Delete account
  • 14. List the current accounts in bank • Need to return to us a collection that represents • Design doesn't have Account1, Account2, Account..., just accounts GET: /accounts Response: [{"id":0,"name":"Mike"}, {...}, {...}]
  • 15. Create new account • Need to create new account in bank with providing name of person • Good practice is returning already created account POST: /accounts json: {"name":"Matt"} Response: {"id":2,"name":"Matt"}
  • 16. Create new credit card • That just a request for creation credit card automatically POST: /accounts/2/creditcards json: {"pin":1111, "cardNumber":2, "cardStatus":"ACTIVE", "remnant":0.0}
  • 17. List the current credit cards of account • Need to return to us a collection of all available credit cards GET: /accounts/2/creditcards Response: [ {"pin":1111, "cardNumber":2, "cardStatus":"ACTIVE", "remnant":0.0} ]
  • 18. Make transaction between two credit cards • Transaction be running during some time • Possible situation when you created just a request for transaction and receive just info when this will be precessed POST: /accounts/2/creditcards json: {"fromCreditCard": "1", "toCreditCard": "2", "amount": "20"} Transaction successfully processed
  • 19. Lock Credit Card • Changed status of credit card PUT: /accounts/2/creditcards/2 {"pin":1111, "cardNumber":2, "cardStatus":"LOCKED", "remnant":20.0}
  • 20. Delete account • No input required • No output required DELETE /accounts/2
  • 21.
  • 22. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 23. Status codes • Status codes indicates the results of the server's attempt to satisfy the request • Broadly divided into categories – 1XX: Informational – 2XX: Success – 3XX: Redirection – 4XX: Client Error – 5XX: Server Error
  • 24. Success Status Codes • 200 OK Everything worked • 201 Created The server has successfully created a new resource Newly created resource’s location returned in the Location header • 202 Accepted The server has accepted the request, but it is not yet complete A location to determine the request’s current status can be returned in the Location header
  • 25. Client Error Status Codes • 400 Bad Request Malformed syntax Should not be repeated without modification • 401 Unauthorized Authentication is required Includes a WWW-‐Authenticate header • 403 Forbidden Server has understood but refuses to honor the request Should not be repeated without modification
  • 26. Client Error Status Codes • 404 Not Found The server cannot find a resource matching a URI • 406 Not Acceptable The server can only return response entities that do not match the client’s Accept header • 409 Conflict The resource is in a state that is in conflict with the request Client should attempt to rectify the conflict and then resubmit the request
  • 27.
  • 28. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 29. Communication between client and server Content types are negotiated using headers: • Client describes what it wants with the Accept header • Server (and client during POST and PUT) describes what it is sending with Content- Type header
  • 30. Common Media Types • Application – JSON: application/json – XML: application/xml – PDF: application/pdf • Text – HTML: text/html – PLAIN: text/plain
  • 31. Addition Media Types • Image – JPEG: image/jpeg • Audio – MP4: audio/mp4 – WEBM: audio/webm • Video – MP4: video/mp4 – WEBM: video/webm • Prefix vnd (vendor specific files) – application/vnd.android.package-archive - for apk files – application/vnd.ms-excel
  • 32. Agenda What is REST? CRUD operations Status codes Media types SpringMVC instruments
  • 33. What other instruments Spring MVC can provide? • @RestController Union of @Controller and @RequestBody annotations • @RequestBody • @RequestMapping value; method; consumes; produces • @PathVariable • @RequestParam
  • 34. What other instruments Spring MVC can provide? • @RequestHeader • @MatrixVariable /owners/{ownerId}/pets/{petId} GET /owners/42;q=11;r=12/pets/21;q=22;s=23 @MatrixVariable(pathVar="petId") Map<String, String> petMatrixVars <mvc:annotation-driven enable-matrix- variables="true"/> • @SessionAttributes • @ModelAttribute • @CookieValue
  • 35. What more? • Testing REST with MockMvc • REST Client • Caching • Version handling • Scaling: CDN (Content Delivery Network)
  • 36. Useful links • Tutorials – http://www.restapitutorial.com/ • Video & Articles – https://www.youtube.com/watch?v=5WXYw4J4QOU – ETags: http://www.infoq.com/articles/etags – Manage REST API versions: http://stackoverflow.com/questions/20198275/how-to-manage-rest-api- versioning-with-spring?answertab=votes#tab- tophttp://stackoverflow.com/questions/20198275/how-to-manage-rest-api- versioning-with-spring?answertab=votes#tab-top – Steps towards the glory of REST: http://martinfowler.com/articles/richardsonMaturityModel.html • Examples from presentation: https://github.com/searhiy/REST-examples • Instruments & Tools – https://github.com/spring-projects/spring-data-rest – http://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate