-1

I'm drawing my API routes.

A user has projects, projects have actors, actors have addresses.

There is no address without an actor, there is no actor without a project, and there is no project without a user.

Would this be the correct way to build the end_point?

GET /users/{user_id}/projects/{project_id}/actors/{actor_id}/addresses

1 Answers1

0

There is no such thing as a REST endpoint. There are resources. -- Fielding, 2018

What you seem to be asking about here is how to design the identifier for your resource.

REST doesn't care what spelling conventions you use for your resource identifiers, so long as they satisfy the production rules described by RFC 3986.

Identifiers that load data into the query part are convenient if you are expecting to leverage HTML forms:

GET /addresses?user={user_id}&project={project_id}&actor=actor_id

But that design is not particularly convenient if you are expecting to use dot segments to reference other resources.

Choosing some alternative that is described by a URI Template will make some things easier down the road.

/users/{user_id}/projects/{project_id}/actors/{actor_id}/addresses

That's fine. Other spellings would also be fine (hint: URL shorteners work).

Broadly, you choose identifier spellings by thinking about the different contexts in which a human being has to look at the URI (documentation for your API, browser histories, access logs, etc.) and choose a spelling that works well in at least one of those settings.

Community
  • 1
  • 1
VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91