I wanted to develop a RESTful
Application with use of CRUD
in Play framework. Unfortunately I can't find a way to define DELETE
and PUT
in the routes of Play. Maybe there is just POST
and GET
available in Play?
Are you sure you cannot use DELETE/PUT? The docs say otherwise.
The HTTP method
The HTTP method can be any of the valid methods supported by HTTP (GET, POST, PUT, DELETE, HEAD).
http://www.playframework.org/documentation/2.0.4/JavaRouting
Play 2.x has not a CRUD module known from 1.x branch (IMHO fortunately), for defining routes using not standard methods like DELETE
or PUT
you need to just use required method in the route:
conf/routes:
PUT /put-item controllers.Application.putItem()
Anyway to use them from the browser methods other than GET
or POST
you'll need to create an AJAX call, There is a large step-by-step sample on this topic, anyway you can also build it with common jQuery.ajax() by defining the request type
$.ajax({
type: "PUT",
url: "@routes.Application.putItem()",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
A good way to define these is using a wildcard (*) This will allow you to use any method valid http method, including those that you have asked about.
For example,
* /items/{id} Items.display
in routes will allow a GET /items/15 or a PUT /items/15. Use wildcards like this to make your route definitions simpler and more flexible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With