What is the best practice for writing REST endpoints
I want to add REST endpoint that will add reservation for some room in hotel. What is the better way to do it. I have 2 solution:
@RequestMapping("api/v1/hotels/hotelId/rooms/roomId/reservations")
some Class Endpoint
@PostMapping
public ReservationApi save(final @RequestBody ReservationApi reservationApi,
final @PathVariable("hotelId") String hotelId,
final @PathVariable("roomId") String roomId) {
final Reservation reservation = reservationMapper.toDomain(reservationApi);
return reservationMapper.toApi(reservationService.save(reservation, hotelId, roomId));
}
and build Reservation on service side
or I have alternative solution where we do not use paths and only API class for creating
@RequestMapping("api/v1/reservations")
@PostMapping
public ReservationApi save(final @RequestBody ReservationApi reservationApi) {
final Reservation reservation = reservationMapper.toDomain(reservationApi);
return reservationMapper.toApi(reservationService.save(reservation));
}