SlideShare une entreprise Scribd logo
1  sur  23
REST principles 
and 
Play routes 
configuration 
Rakesh Chouhan 
Date-24-01-2013
REST 
(Representational State Transfer) 
● REST is a Style of the Software architecture for 
distributed system such as World wide web. 
● It is nothing but using the current feature of web in 
simple and effective way. some of the amazing feature 
of web are : 
o Widely accepted HTTP protocol. 
o Standard and Unified method PUT, POST, GET and 
DELETE. 
o Stateless nature of HTTP protocol. 
o Easy to use URI (Uniform resource identifier) format 
to locate any resource. 
It is a set of constraints not rules.
HTTP VERBS 
● GET 
● POST 
● PUT 
● DELETE 
● HEAD 
● OPTION
Principles of REST services 
● Everything is a Resource. 
● Every resource is identified by unique identifier. 
● Use simple and uniform interfaces. 
● Communication is done by representation. 
● Be stateless.
Principles of REST services 
● Everything is a Resource
Principles of REST services 
● Every resource is identified by unique identifier 
Example: 
Customer Data URI 
Get all Customer list GET http://www.custapp.com/employee/all 
Get Customer by ID GET http://www.custapp.com/employee/101
Principles of REST services 
● Use simple and Uniform interfaces.
Principles of REST services 
● Use simple and Uniform interfaces. 
eg : we exposed the customer and order data on the web, 
Normal Method HTTP Method Uniform URI 
AddCustomer PUT /customer/raj 
InsertOrders PUT /order/001 
SelectCustomer GET /customer/raj 
getOrders GET /order/001 
DeleteCustomer DELETE /customer/raj 
RemoveOrder DELETE /order/001
Principles of REST services 
● Communication is done by representation. 
The client and server exchanging the representations.
Principles of REST services 
● Communication is done by representation. 
eg : we want to create a customer, we send some kind of 
representation to the server using HTTP PUT, 
<customer> 
<name>raj</name> 
<address>Vashi</address> 
<customer> 
and the server send some other representation to show that 
the resource is created, and move towards the next step. 
<customer> 
<name>raj</name> 
<next>http://www.custapp.com/customers/Orders</next> 
</customer>
Principles of REST services 
● Be Stateless. 
Every request should be independent. 
It means that once the request is processed, the next 
request of the web visitor, does not have to come back to 
same machine. 
eg. VE.Box Restful services.
Play routes 
Play routes consist of the HTTP method and URI and both 
are associated with and Action generator ( controller's 
static method) 
routes are defined in "conf/routes" file. 
Modules doesn't have the routes file, if we deploy the 
routes in module, it will override the main application's 
routes file. 
route syntex : 
HTTP Method URI Action 
GET /customer/:id controller.Application.selectCustomer(id : 
Long)
Play URI patterns 
● Static path 
GET /Customer/all controller.Customer.list() 
● Dynamic parts 
GET /Customer/:id controller.Customer.getCustomer(id: Long) 
GET /Customer/:id/:name controller.Customer.getCustomer(id: Long, 
name :String)
Play URI patterns 
● Dynamic parts spanning several 
dynamic part using the *id syntax 
GET /files/*name 
controllers.Application.download(name) 
eg : GET http://www.custapp.com/files/image/001.gif 
then the dynamic part will capture the " image/001.gif". 
● Dynamic parts using regular expression. 
regular expression for a dynamic part, using the $id<regex> syntax 
GET /customer/$id< [0-9]+> 
controller.customer.getCust(id: Long)
Action generator Methods 
● The last part of the route definition. 
● If the action method doesn't have any parameter name just give the fully 
qualified name 
GET / controller.CustApp.home() 
● If the action method defines the parameter, the corresponding parameter 
value will be searched in URI, either extracted from the URI path or from 
the query String 
Extract the page parameter from the path. 
i.e. http://www.custapp.com/index 
GET /:page controllers.CustApp.show(page) 
Extract the page parameter from the query string. 
i.e. http://www.custapp.com/?page=index 
GET / controllers.Application.show(page)
Parameter Type 
● Default parameter type is String 
GET /:page controllers.CustApp.show(page) 
page parameter is String here 
● Parameter with fixed value. 
GET / 
controllers.CustApp.show(page = "home") 
GET /:page controllers.CustApp.show(page) 
● Parameter with default value 
GET / 
controllers.CustApp.show( page: Integer ?= 1)
Assets 
● Serves the application’s static resources such as JavaScript, CSS and 
images. 
● The play 2.0 has a built-in controller Assets with the action "at(path:String, 
file: String )" to serve the public data. 
GET /assets/*file controllers.Assets.at(path="/public", file) 
we can also get the static data using this 
GET /jquery controllers.Assets.at("/public", "javascripts/jquery.js")
Assets 
● Etag support 
Etag is an identifier assigned by the server to a specific version of resource 
found at the URL, if resource available at the URL change the new Etag is 
assigned. Comparing ETags only makes sense with respect to one URL— 
ETags for resources obtained from different URLs may or may not be equal. 
● The Assets Controller automatically manage the ETag HTTP header, the 
ETag value is generated through the resource name and file modification 
date. 
● when the browser makes a request specifying the ETag header the server 
can respond with the "304 not modified"
Assets 
● Gzip support 
If a resource with the same name but using a .gz suffix is found, the Assets 
controller will serve this one by adding the proper HTTP header: 
Content-Encoding: gzip 
● Cache-Control directive 
Etag is enough for caching but if we want to add the custom cache-control for 
any specific resource then in application.conf file we have to add the following 
line : 
"assets.cache./public/javascript/jquery.js" = "max-age=1000"
Assets 
● By default the play compile all managed assets, the compilation process 
clean and compile all the managed resources. This is the safest strategy 
since tracking dependencies can be very tricky with front end technologies. 
If you are dealing with a lot of managed assets this strategy can be very 
slow. For this reason there is a way to recompile only the change file and 
its supposed dependencies. You can turn on this experimental feature by 
adding the following to your settings: 
incrementalAssetsCompilation := true 
in application.conf file.
Reverse Routing 
in conf/routes file 
Hello action 
GET /error/:errorString controllers.CustApp.showError(errorString) 
and we want to redirect our application control to the error page, then 
public static Result index(Long id) { 
if( id <= 0){ 
return redirect(controllers.routes.CustApp.showError("Invalid ID")); 
} 
return ok("OK"); 
}
Imp links 
https://docs.google.com/viewer?a=v&q=cache:T_r8a7FMSlEJ:info.apigee.com/ 
Portals/62317/docs/web%2520api.pdf+&hl=en&gl=in&pid=bl&srcid=ADGEESg 
RRCSELrGALLSKNIL9rv4_9_LE2aU6IlkjLuIfsnhxedcCBaCUQbl_WztHIWO5p 
YIGXdfOQu548ONbARnxuz1xSFNefne_CAYYZES83umHNuFps3Wnw5JVAE 
Pd8gjY8RBSGBw1&sig=AHIEtbTOsWoJBz-AeMkXSAVrjaf0j58rhA 
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rj 
a&sqi=2&ved=0CDkQtwIwAQ&url=http%3A%2F%2Fvimeo.com%2F17785736 
&ei=ERQBUdOuKsPprQfWkoCIBQ&usg=AFQjCNHSv7WOu5AyLZ_NIyrZtzMl 
k-4W8g&bvm=bv.41524429,d.bmk
Thank you

Contenu connexe

Tendances

Tool it Up! - Session #2 - NetPanel
Tool it Up! - Session #2 - NetPanelTool it Up! - Session #2 - NetPanel
Tool it Up! - Session #2 - NetPanel
toolitup
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
Eleonora Ciceri
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
Harry Potter
 

Tendances (20)

Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
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
 
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data typePostgrtesql as a NoSQL Document Store - The JSON/JSONB data type
Postgrtesql as a NoSQL Document Store - The JSON/JSONB data type
 
Apache Gobblin
Apache GobblinApache Gobblin
Apache Gobblin
 
Tool it Up! - Session #2 - NetPanel
Tool it Up! - Session #2 - NetPanelTool it Up! - Session #2 - NetPanel
Tool it Up! - Session #2 - NetPanel
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 
Redux Universal
Redux UniversalRedux Universal
Redux Universal
 
Using redux
Using reduxUsing redux
Using redux
 
Async Server Rendering in React+Redux at NYTimes (redux-taxi)
Async Server Rendering in React+Redux at NYTimes (redux-taxi)Async Server Rendering in React+Redux at NYTimes (redux-taxi)
Async Server Rendering in React+Redux at NYTimes (redux-taxi)
 
RESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test themRESTful application with JAX-RS and how to expose and test them
RESTful application with JAX-RS and how to expose and test them
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
A Tour of PostgREST
A Tour of PostgRESTA Tour of PostgREST
A Tour of PostgREST
 
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
 
Catalyst MVC
Catalyst MVCCatalyst MVC
Catalyst MVC
 
How to build a rest api.pptx
How to build a rest api.pptxHow to build a rest api.pptx
How to build a rest api.pptx
 
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
 
AJAX - An introduction
AJAX - An introductionAJAX - An introduction
AJAX - An introduction
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
 
Request-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails AppRequest-Response Cycle of Ruby on Rails App
Request-Response Cycle of Ruby on Rails App
 

Similaire à REST principle & Playframework Routes

MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESSMERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
annalakshmi35
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
Anuchit Chalothorn
 

Similaire à REST principle & Playframework Routes (20)

Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
ExpressJS and REST API.pptx
ExpressJS and REST API.pptxExpressJS and REST API.pptx
ExpressJS and REST API.pptx
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESSMERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
 
23003468463PPT.pptx
23003468463PPT.pptx23003468463PPT.pptx
23003468463PPT.pptx
 
(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEP(ATS6-DEV03) Building an Enterprise Web Solution with AEP
(ATS6-DEV03) Building an Enterprise Web Solution with AEP
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
Android App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web ServicesAndroid App Development 06 : Network &amp; Web Services
Android App Development 06 : Network &amp; Web Services
 
Rest service in mule
Rest service in mule Rest service in mule
Rest service in mule
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
Rest Service In Mule
Rest Service In Mule Rest Service In Mule
Rest Service In Mule
 
A Deep Dive into RESTful API Design Part 2
A Deep Dive into RESTful API Design Part 2A Deep Dive into RESTful API Design Part 2
A Deep Dive into RESTful API Design Part 2
 
Restful webservices
Restful webservicesRestful webservices
Restful webservices
 
SOAP vs REST
SOAP vs RESTSOAP vs REST
SOAP vs REST
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 

Dernier

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
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
VictoriaMetrics
 
%+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
 
+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
 
%+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
 
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
 

Dernier (20)

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
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
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...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
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
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
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
 
%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 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...
 
+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...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
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 - 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...
 
%+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...
 
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...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 

REST principle & Playframework Routes

  • 1. REST principles and Play routes configuration Rakesh Chouhan Date-24-01-2013
  • 2. REST (Representational State Transfer) ● REST is a Style of the Software architecture for distributed system such as World wide web. ● It is nothing but using the current feature of web in simple and effective way. some of the amazing feature of web are : o Widely accepted HTTP protocol. o Standard and Unified method PUT, POST, GET and DELETE. o Stateless nature of HTTP protocol. o Easy to use URI (Uniform resource identifier) format to locate any resource. It is a set of constraints not rules.
  • 3. HTTP VERBS ● GET ● POST ● PUT ● DELETE ● HEAD ● OPTION
  • 4. Principles of REST services ● Everything is a Resource. ● Every resource is identified by unique identifier. ● Use simple and uniform interfaces. ● Communication is done by representation. ● Be stateless.
  • 5. Principles of REST services ● Everything is a Resource
  • 6. Principles of REST services ● Every resource is identified by unique identifier Example: Customer Data URI Get all Customer list GET http://www.custapp.com/employee/all Get Customer by ID GET http://www.custapp.com/employee/101
  • 7. Principles of REST services ● Use simple and Uniform interfaces.
  • 8. Principles of REST services ● Use simple and Uniform interfaces. eg : we exposed the customer and order data on the web, Normal Method HTTP Method Uniform URI AddCustomer PUT /customer/raj InsertOrders PUT /order/001 SelectCustomer GET /customer/raj getOrders GET /order/001 DeleteCustomer DELETE /customer/raj RemoveOrder DELETE /order/001
  • 9. Principles of REST services ● Communication is done by representation. The client and server exchanging the representations.
  • 10. Principles of REST services ● Communication is done by representation. eg : we want to create a customer, we send some kind of representation to the server using HTTP PUT, <customer> <name>raj</name> <address>Vashi</address> <customer> and the server send some other representation to show that the resource is created, and move towards the next step. <customer> <name>raj</name> <next>http://www.custapp.com/customers/Orders</next> </customer>
  • 11. Principles of REST services ● Be Stateless. Every request should be independent. It means that once the request is processed, the next request of the web visitor, does not have to come back to same machine. eg. VE.Box Restful services.
  • 12. Play routes Play routes consist of the HTTP method and URI and both are associated with and Action generator ( controller's static method) routes are defined in "conf/routes" file. Modules doesn't have the routes file, if we deploy the routes in module, it will override the main application's routes file. route syntex : HTTP Method URI Action GET /customer/:id controller.Application.selectCustomer(id : Long)
  • 13. Play URI patterns ● Static path GET /Customer/all controller.Customer.list() ● Dynamic parts GET /Customer/:id controller.Customer.getCustomer(id: Long) GET /Customer/:id/:name controller.Customer.getCustomer(id: Long, name :String)
  • 14. Play URI patterns ● Dynamic parts spanning several dynamic part using the *id syntax GET /files/*name controllers.Application.download(name) eg : GET http://www.custapp.com/files/image/001.gif then the dynamic part will capture the " image/001.gif". ● Dynamic parts using regular expression. regular expression for a dynamic part, using the $id<regex> syntax GET /customer/$id< [0-9]+> controller.customer.getCust(id: Long)
  • 15. Action generator Methods ● The last part of the route definition. ● If the action method doesn't have any parameter name just give the fully qualified name GET / controller.CustApp.home() ● If the action method defines the parameter, the corresponding parameter value will be searched in URI, either extracted from the URI path or from the query String Extract the page parameter from the path. i.e. http://www.custapp.com/index GET /:page controllers.CustApp.show(page) Extract the page parameter from the query string. i.e. http://www.custapp.com/?page=index GET / controllers.Application.show(page)
  • 16. Parameter Type ● Default parameter type is String GET /:page controllers.CustApp.show(page) page parameter is String here ● Parameter with fixed value. GET / controllers.CustApp.show(page = "home") GET /:page controllers.CustApp.show(page) ● Parameter with default value GET / controllers.CustApp.show( page: Integer ?= 1)
  • 17. Assets ● Serves the application’s static resources such as JavaScript, CSS and images. ● The play 2.0 has a built-in controller Assets with the action "at(path:String, file: String )" to serve the public data. GET /assets/*file controllers.Assets.at(path="/public", file) we can also get the static data using this GET /jquery controllers.Assets.at("/public", "javascripts/jquery.js")
  • 18. Assets ● Etag support Etag is an identifier assigned by the server to a specific version of resource found at the URL, if resource available at the URL change the new Etag is assigned. Comparing ETags only makes sense with respect to one URL— ETags for resources obtained from different URLs may or may not be equal. ● The Assets Controller automatically manage the ETag HTTP header, the ETag value is generated through the resource name and file modification date. ● when the browser makes a request specifying the ETag header the server can respond with the "304 not modified"
  • 19. Assets ● Gzip support If a resource with the same name but using a .gz suffix is found, the Assets controller will serve this one by adding the proper HTTP header: Content-Encoding: gzip ● Cache-Control directive Etag is enough for caching but if we want to add the custom cache-control for any specific resource then in application.conf file we have to add the following line : "assets.cache./public/javascript/jquery.js" = "max-age=1000"
  • 20. Assets ● By default the play compile all managed assets, the compilation process clean and compile all the managed resources. This is the safest strategy since tracking dependencies can be very tricky with front end technologies. If you are dealing with a lot of managed assets this strategy can be very slow. For this reason there is a way to recompile only the change file and its supposed dependencies. You can turn on this experimental feature by adding the following to your settings: incrementalAssetsCompilation := true in application.conf file.
  • 21. Reverse Routing in conf/routes file Hello action GET /error/:errorString controllers.CustApp.showError(errorString) and we want to redirect our application control to the error page, then public static Result index(Long id) { if( id <= 0){ return redirect(controllers.routes.CustApp.showError("Invalid ID")); } return ok("OK"); }
  • 22. Imp links https://docs.google.com/viewer?a=v&q=cache:T_r8a7FMSlEJ:info.apigee.com/ Portals/62317/docs/web%2520api.pdf+&hl=en&gl=in&pid=bl&srcid=ADGEESg RRCSELrGALLSKNIL9rv4_9_LE2aU6IlkjLuIfsnhxedcCBaCUQbl_WztHIWO5p YIGXdfOQu548ONbARnxuz1xSFNefne_CAYYZES83umHNuFps3Wnw5JVAE Pd8gjY8RBSGBw1&sig=AHIEtbTOsWoJBz-AeMkXSAVrjaf0j58rhA https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rj a&sqi=2&ved=0CDkQtwIwAQ&url=http%3A%2F%2Fvimeo.com%2F17785736 &ei=ERQBUdOuKsPprQfWkoCIBQ&usg=AFQjCNHSv7WOu5AyLZ_NIyrZtzMl k-4W8g&bvm=bv.41524429,d.bmk