0

I'm developing a game website where accounts have characters. I'm using the routes:

account/{action} //execute `action` on the current account
character/{name}/{action} //execute `action` on specific character

But I need to delete and undelete (they are soft-deleted) characters, and while using a form is the right way for delete, it becomes unnecessary (is it?) bloat when I can use just a GET link to character/{name}/delete. Also, there is no verb for undeleting/restoring.

What is the correct and easy way (or both if there isn't the perfect way) to workaround this?

ranisalt
  • 1,861
  • 1
  • 18
  • 35

2 Answers2

1

You could have a RESTful version if your URLs have nouns instead of verbs, such as :

character/{name}/achievements or

character/{name}/travels

To solve your active/inactive account problem, you could do :

GET/PUT account/activity
Pak
  • 1,758
  • 19
  • 27
0

Already not restful, in which you are determining the action based on the route, not based on the verb. So that said, make a new route that is undelete (i.e. character/{name}/undelete), your already not REST so another route shouldn't matter. If you are looking for RESTful then the route should stay account/{character} and the verb determines the action(i.e. GET,PUT, POST DELETE to the same route). Now since you are not actually deleting, I would learn towards a POST (or perhaps PUT) for both i.e. updaing the entity to delete (or inactive), or updating it to undelete (active again)

OJay
  • 4,156
  • 2
  • 22
  • 40
  • Actually operations may be treated as resources as well. Just to give an example: Suppose you have an Order resource. Orders are addressable with URLs like /Order/{OrderId} (IE: /Order/123 returns representation of Order 123). What if i want to "purchase" that order? I dont think its wrong to have an URL like /Order/123/purchase. HTTP methods are more related to the idempotency and safety of an action (and based on that, "purchase" will be a PUT, POST or whatever other method that fits to the case). In the particular case described on original post, "undelete" is an operation IMHO. – juancancela Mar 07 '14 at 05:12
  • @juancancela sure, it's "okay" to have a URL like `/Order/123/purchase`, but **it is not RESTful.** – Matt Ball Mar 07 '14 at 05:47
  • @MattBall why is not restful? And more important, what it would be in your opinion the 'rest way' to manage that scenario? – juancancela Mar 07 '14 at 12:18
  • I think you are being just too strict with REST. I'm leaning towards @juancancela interpretation and the answer by Pak, since most applications may need more than just create/show/update all/destroy – ranisalt Mar 08 '14 at 02:39
  • 2
    @ranisalt I disagree. REST itself is strict. I suggest that you take some time to learn exactly what REST/RESTful do and don't mean. Start with http://stackoverflow.com/q/671118/139010 and consider picking up a book after that. – Matt Ball Mar 08 '14 at 16:42
  • Restful is not strict, basically because There isn't something like a "REST standard" (in fact, i remember a presentation where Mike Amundsen laughs about something like that). Anyway, the link you provide is a good list to take into account before implementing a REST API. – juancancela Mar 13 '14 at 04:54