Matthew Hartz Matthew Hartz - 8 months ago 58
reST (reStructuredText) Question

Rest API Design Establishing Connection between the same resource

I have a resource called clients. We are now creating a system where we can link clients with other clients to create subclients. We are creating a table to represent this called clientconnections, which contains clientId and subclientId.

Now to establish this, we are doing it via an invite system (so we'll need an invite action api).

What is the best way to represent this in a restful way?

can be through a simple API such as:

But establishing the connection via a rest API is hard. Here is my original idea... but i definitely think it's wrong.

/clients/{clientid}/connections/{clientid2 doh}/invite

or this but this doesn't seem right either


Any suggestions would be great!



There's a bunch of different ways to think about this, I don't think there's one valid approach but I think I would do one of the following:

  1. Treat clients that have and have not accepted as the same thing, just with a different status.
  2. Treat 'invitations' as its own separate thing altogether. Only when the invitation has been accepted, a 'connection' is being created.

There is no real right or wrong here. My main advice would be is: keep it simple.