Hexxx
Hexxx

Reputation: 59

The same URI path for REST with different methods OR different URI paths?

What is the better way of using HTTP methods for REST:

First variant:

Send different HTTP methods to the same URL:

URL : item/{id}   method : DELETE   ---- DELETE item<br>
URL : item/{id}   method : PUT   ---- PUT item<br>
URL : item/{id}   method : GET   ---- GET item<br>

OR second:

Have a different URL for each HTTP method, and send each verb to its corresponding URL:

URL : deleteitem/{id} OR item/delete/{id}   method: DELETE ---- DELETE item<br>
URL : putitem/{id} OR item/put/{id}         method: PUT ----    PUT item<br>
URL : getitem/{id} OR item/get/{id}         method: GET ----    GET item<br>

Upvotes: 3

Views: 2239

Answers (1)

Raedwald
Raedwald

Reputation: 48702

The first variant, with the methods applied to the same URI, is the REST way of doing things. With REST, you do the following:

  • Identify a set of resources that your web application manipulates: items in your case.
  • Give each resource an identifier (a URI) that the application and its clients can use to indicate a particular resource: item/{id} in your case.
  • Identify manipulations of the resources that clients can perform.
  • Use an HTTP method (verb) applied to a URI (noun) to express those manipulations.
  • Have clients perform those operations by sending HTTP requests to the server, using those HTTP methods and URIs.

Upvotes: 5

Related Questions