user6123723
user6123723

Reputation: 11106

Naming conventions for a few operations (verbs) in REST

I'm trying to not use verbs when designing a REST api but struggling to re-imagine operations as resources (as in REST)

Here are a few

/guest/accountnumber/isValid/{username} (returns a Boolean by checking if account number is valid)
/user/associateAccount/{firstAcc}/{secondAcc} (returns a Boolean. Links up the two passed in accounts)

I really do not want to intentionally follow a bad practice and kill the spirit of REST but I'm struggling to re think this as resource state transfers instead of fowl XML RPC style operations or remote method invocations. Any help is appreciated!

Upvotes: 0

Views: 815

Answers (1)

Sam
Sam

Reputation: 9944

Does the boolean indicate the success of the operation? HTTP response codes can be used for that.

For the "associated accounts", imagine the association itself as an object. These objects can be imagined as being in a 'folder' under the account they refer to.

You could have PUT /accounts/{firstAcc}/associations/{secondAcc} return an HTTP code indicating whether the accounts were successfully associated (say 201 Created or 409 Conflict). DELETE /accounts/{firstAcc}/associations/{secondAcc} can be used to remove the link.

For your other example, I don't see exactly what you're trying to express. Is it just a check to see if an account exists? For that, I would use HEAD /accounts/{number}. It would return 200 if the account is valid and 404 if not.

Upvotes: 1

Related Questions