I am currently designing a REST API. I have got a Group
Entity and an Event
Entity. One Event
belongs to exactly one Group
, but one Group
can have multiple Events
.
Groups
are accessed via
/groups/group/{groupId}
I am not sure about where to put the Event
endpoint:
/groups/group/{groupId}/events/event/{eventId}
or just
/events/event/{eventId}
Posting new Events
into a Group
is easier with the upper, whereas just getting data about one Event
is easier with the lower approach.
Which of them should I use, or should I even "mix" them? (one for GET
, one for POST
)
First of all your REST basic endpoints should be like this:
/groups
/groups
/events
/events
So now come on you want to fetch an event of the specific group by id
like you tried here /groups/group/{groupId}/events/event/{eventId}
right?
you can fetch all events of a group like this :
/events?group_id={groupId}
like this here you can implement. /groups?event_id={event_Id}
/groups/{id}?event={eventId}
that 3rd route or endpoint of Group's REST above and same for vice-varsa.