user2192634
user2192634

Reputation: 13

Remove or create 'Has a 'relationship between entities in REST

I have a destination pool entity that can have many destination entities. How do I have a REST URL request to add a destination to destination pool or delete a destination from destination pool.

Right now I am using

/destinationpool/{destinationpool-name}/add/{destination-name} to add a destination to a destination pool

/destinationpool/{destinationpool-name}/delete/{destination-name} to remove a destination from a destination pool

Both being PUT requests

Upvotes: 0

Views: 194

Answers (1)

SteveJ
SteveJ

Reputation: 3313

If you are trying to truly be RESTful, your CRUD actions should be indicated by your http verbs, not your url. I tend to place my inputs as part of the url parameters so that it mimics a standard function call in which you have the function definition and the parameters.

to create (post vs put)

[POST]
/destinationpool/{destinationpool-name}/destinations
(url).../destinationpool/{destinationpool-name}/destinations?destination-name=<name>

to delete

[DELETE]
/destinationpool/{destinationpool-name}/destinations
(url)..../destinationpool/{destinationpool-name}/destinations?destination-name=<name>

When you read the above, it is clear that you are placing something into the destinations relation of destination pool (or deleting something from).

As a side note - names are dangerous due to uniqueness, spelling, capitalization, etc. Ids are much better.

Upvotes: 1

Related Questions