Search code examples
httprestplayframeworkplayframework-2.2nested-routes

Is it possible to use nested resource in case of POST?


I use Play Framework 2.2.X.

Is it possible to map this route?:

POST /api/constructors/:constructorId/cars  CarCrudController.create(constructorId)

I get a BadRequest (code 400) when hitting this route.

IMO, it seems that Play allows nested resources only for reads: GET instead of POST.

Is it possible?


Solution

  • Nested routes are supported in any HTTP method. You can checkout the samples from the github for some examples. The computer-database example, has the following routes.conf:

    # Delete a computer
    POST    /computers/:id/delete       controllers.Application.delete(id:Long)
    

    The bad request response could be related with the content-type of your request or the post content itself, and nothing to do with the nested routes.