1

I am new to restful services and willing to get some ideas from the experts.

The application which will be accessing my service is having a datatable-grid (each row of the grid represents an Employee Object/Entity) where user can delete more than 1 records at a time(based on the number of checkbox selected by the user). In such kind of a delete operating how will be the URL representation and how will the data be send to the service?

My Idea

Since the number of rows deleted by the differs (based on the number of checkbox selected by the user), hence I am opting for the query string and below will be the URL representation using which I can get the data in my service:

/deleteEmployees?id=1,2,3

i.e. a comma seperated values of the id's which will uniquely identify a record in the table.

Based on my Idea, I have a few questions:

1) The query String mentioned above contains of comma-seperated values (i.e. Ids). Is it a valid URL where query strings will contain this kind of values?

2) Is there any restrictions in defining the query strings of an URL (like the way I did using csv)?

3) Any other alternative of achieving the same in a better and efficient manner?

P.S. I am new on this and hence looking for different ideas from the experts and try to understand what is correct and what is not.

WhoAmI
  • 819
  • 4
  • 18
  • 35
  • 1
    I don't think REST really likes deleting whole subset of elements of a resource at a time. If you had to do it this way, CSV is fine in a url. You could also have the CSV as a custom header value in the HTTP request. See [here](http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) for restrictions. I would instead loop through the checkbox selections and make a DELETE HTTP request on `/employee/{id}` – Sotirios Delimanolis May 24 '13 at 14:45
  • Thanks for the reply. your alternative of looping through it is also fine. But, isn't it like making the service call n times rather than one at a go? Please comment on this. – WhoAmI May 24 '13 at 15:28
  • That's exactly what it is. It might just be more REST-like since you are interacting with a resource with HTTP methods (ex: DELETE) instead of with actions like `/deleteEmployees` – Sotirios Delimanolis May 24 '13 at 15:33
  • The wiki article for [`REST`](https://en.wikipedia.org/wiki/Representational_state_transfer) describes how resources should be accessed. Otherwise, you can read the whole [REST Thesis](http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm). It's just a feeling I've had while working with RESTful architectures. – Sotirios Delimanolis May 24 '13 at 15:38
  • The option with a header might even be better. If you're accessing the whole set of `Employee` resources at `/employees`, you can send a DELETE HTTP request, with a header like `Employees-To-Delete: 1,2,3`. That seems more REST-like to me. – Sotirios Delimanolis May 24 '13 at 15:40
  • Thanks for the response...I will wait for some other experts to comment on this as well – WhoAmI May 24 '13 at 15:40

1 Answers1

3

A comma separated list of Employee ids is a fine way to do it, but I wouldn't put it in a URL with an action in it, ie. /deleteEmployees?id=1,2,3. REST is more about identifying resources, rather than actions, in URLs. I would either loop through each one of the employee ids to delete and send an HTTP DELETE request for each

DELETE /employees/1 HTTP/1.1
DELETE /employees/2 HTTP/1.1
DELETE /employees/3 HTTP/1.1

Another alternative is to send one HTTP DELETE request to a URL like /employees, keeping the suggested REST identification of resources and using HTTP methods. You would pass the list of ids in an HTTP header.

DELETE /employees HTTP/1.1
Employees-To-Delete: 1,2,3

Take a look at this answer for character restrictions in URLs.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724