-3

TutorialsPoint defines the following methods in context of RESTful design:

URI           HTTP      Body           Result
-----------------------------------------------------------------
listUsers     GET       empty          Show list of all the users
addUser       POST      JSON string    Add details of new user
deleteUser    DELETE    JSON string    Delete an existing user
:id           GET       empty          Show details of a user

I think this is misleading, because it's not RESTful.

A RESTful design would be as following:

URI          HTTP      Body           Result
----------------------------------------------------------------
users        GET       empty          Show list of all the users
users        POST      JSON string    Add details of new user
users        DELETE    empty          Delete an existing user
users/:id    GET       empty          Show details of a user

Is my understanding of RESTful correct?


Regardless of definition of RESTful, in my opinion, TutorialsPoint presented wrong design, because deleteUser inside URL duplicates information that is already passed as DELETE HTTP action, which violates universal principle of Once And Only Once.

alpav
  • 2,972
  • 3
  • 37
  • 47

2 Answers2

2

Yes your understanding is correct. That tutorial is misleading.

Graham
  • 7,431
  • 18
  • 59
  • 84
busse
  • 1,761
  • 14
  • 25
2

The first set of endpoints is a bad design for a REST API. It's all about RPC (and DELETE requests should not have a payload).

The second set of endpoints are resource-orientated and that's what you want in a REST API. The URI identifies the resource and the HTTP method expresses the operation over the resource.


However the REST architecture goes much beyond the URIs design.

The REST architectural style is protocol independent, but it's designed over the HTTP protocol most of the time.

The fundamental concept in a RESTful application is the resource. And resources can have different representations. For more details, this answer can be helpful.

To be considered RESTful, an application must follow a set of constraints defined in the chapter 5 of Roy Thomas Fielding's dissertation:

Community
  • 1
  • 1
cassiomolin
  • 124,154
  • 35
  • 280
  • 359
  • What do you mean "URLs by themselves are not RESTful" ? I think RESTful design around resources implies that URLs will contain resource address and not action address. At least they should not duplicate what is already passed as HTTP request type. – alpav Jun 01 '17 at 23:28
  • @alpav The _RESTful_ concept does not depend _only_ on how the URLs are designed. The URLs must be resource-oriented when designing REST over the HTTP protocol, but there's also a set of constraints that must be respected. – cassiomolin Jun 01 '17 at 23:34
  • Yes, resource oriented URLs are not the only implication of RESTful design requirements, but is it an implication ? Can action be inside URLs in any RESTful design ? I think it cannot. – alpav Jun 01 '17 at 23:37
  • @alpav In REST applications over HTTP, the URI must be used to identify a resource while the HTTP method must be used to express the operation. So, yeah, the first set of endpoints is a bad design for a REST API. – cassiomolin Jun 01 '17 at 23:47