Pretty simple situation.
My model is 1 Product has many Bookings
the api that I have to expose is just for bookings, the product part is just description and some price that has not to be edited.
so my desired endpoints are:
GET - List of all bookings POST - Create new booking PUT - Update existing Booking
The booking contains product reference but I don't want the endpoint to be "related" with the products so I keep the mapping like this:
@RequestMapping(value = "/bookings", method= RequestMethod.GET) public List<Booking> bookingsList(){ ...
My question is about the Create endpoint. Right now it's like this
@RequestMapping(value = "/{productId}/bookings",method= RequestMethod.POST) public String create(@PathVariable String productId,@RequestBody Booking input){ ...
As you can see I had to use a PathVariable to pass the productId
I was wondering if there is a way to keep the endpoint just /bookings and still pass the productId without create a specific "request model" just for deserialization. From my RoR experience params were generic and can contains lot's of fields not properly related to a specific model(or in this case is only the ID not the object)
I am confused. If the
Booking
object has aproductId
, you could perfectly have the endpoint you want and grab that value from theRequestBody
. I am sure I am missing something.