Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a resource in a RESTful way

Tags:

rest

What is best practice for renaming a resource in a RESTful way? Let's say my users can maintain named lists of things with the uri

http://example.org/users/{userName}/lists/{listName}

I want to give my users an API to rename a certain list. What is the preferred way?

I came up with the following so far:

  • POST to to the list resource with the post-data "newname=..."
  • PUT the list to the new URI and then DELETE the old URI

What is the right way to do this?

like image 764
Florian Fankhauser Avatar asked Oct 23 '09 19:10

Florian Fankhauser


People also ask

What is a RESTful resource?

What is a Resource? REST architecture treats every content as a resource. These resources can be Text Files, Html Pages, Images, Videos or Dynamic Business Data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ Global IDs.

What is resource in REST API with example?

Resources are the basic building block of a RESTful service. Examples of a resource from an online book store application include a book, an order from a store, and a collection of users. Resources are addressable by URLs and HTTP methods can perform operations on resources.

What is resource path in REST API?

You can set the path or suffix used for a REST resource included in a REST API descriptor. By default, each REST resource in a REST API descriptor derives its path from the namespace of the REST resource. For example, if the REST resource is named myREST. myRESTResource, the path is “/myREST. myRESTResource”.

DOES THE REST API ID change?

If the PUT results in the server moving the underlying resource, the ID can change.


1 Answers

First step is fine, but I suggest you not to delete old URI, because every link to that resource will be break. instead return HTTP Code 301 "Moved Permanently"

http://en.wikipedia.org/wiki/HTTP_301

like image 195
rachvela Avatar answered Oct 17 '22 06:10

rachvela