Search code examples
restapi-designrestful-url

multiple path params vs. query params in a RESTful API for POST?


I am trying to implement a restful API

I have an entity called Programme ( description and location details)

I have entity called Timing ( Programme + start time + end time)

I have entity called Check-In ( Timing + User Details )

Scenario: I need Check-In for Timings available,

How should be the ideal URL for the POST request, Option A

POST /programme/:id/timing/:id/check-in
query param: null

Option B

POST /check-in
request body: {programme=id,timing:id}

the first approach will exactly use the id in the path param and directly identifies the resource In the second approach, the consumer tells the type of resource, in the filter conditions mentions the type of resource.

Note: we are using UUID for Programme and Timing resource which will make the URL slightly large


Solution

  • If you are going the Restful way, then you want to identify proper resources and have CRUD operations on those resources.

    There are 3 resources: - Programme - User - Schedule(Timing is a bad resource name for this)->belongs to-> Programme - Register->belongs to(User, Schedule)

    so to register, my restful endpoint will look like

    POST /register BODY {user_id: user1, schedule_id : s1}