I have a create
action in a Play! framework controller that should return the HTTP status code Created
and redirect the client to the location of the created object.
public class SomeController extends Controller {
public static void create() {
Something something = new Something();
something.save();
response.status = StatusCode.CREATED; // Doesn't work!
show(something.id);
}
public static void show(long id) {
render(Something.findById(id));
}
}
See also method chaining in the Play! framework documentation.
The code above returns the status code 302 Found
instead of 201 Created
. What can I do to let Play return the correct status (and Location
header)?