Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what situation should the client choose the unique resource ID for REST URIs and in which should the server specify it?

Tags:

rest

http

uri

api

It looks like there are two ways I can make my REST API. I can have users created with a POST without specifying the URI and it will create the user and return the URI OR I can have the create the users with a PUT and specify the URI themselves.

When should one be used over the other? The key difference here is that in one method MY system is deciding what the unique ID and thus URI for the resource should be, in the other situation THEY are specifying what it should be when I create.

like image 636
MetaGuru Avatar asked Jun 08 '11 20:06

MetaGuru


People also ask

Do all resources have unique URI in REST API?

RESTful clients use URLs to manipulate resources. Each resource must have its own unique URL. Some URL patterns have a collection path with a unique identifier appended.

What is URI explain its purpose in REST based web services what is its format?

A URI is of the following format − <protocol>://<service-name>/<ResourceType>/<ResourceID> Purpose of an URI is to locate a resource(s) on the server hosting the web service. Another important attribute of a request is VERB which identifies the operation to be performed on the resource.

What are the important points to consider when designing a REST API?

Be Clear with Versioning REST APIs should have different versions, so you don't force clients (users) to migrate to new versions. This might even break the application if you're not careful. One of the commonest versioning systems in web development is semantic versioning. An example of semantic versioning is 1.0.

Should URIs be designed by the client?

URIs must be constructed by the client. URIs should be short in length. URIs should be case-sensitive. HTTP verbs should be used instead of operation names in URIS.


1 Answers

It basically comes down to whether you are willing to cede the control of resource naming to the client.

The biggest issue simply being dealing with conflicts (If I PUT /photo.png and you PUT /photo.png, is that OK?).

Answer those questions, and you're on your way.

like image 94
Will Hartung Avatar answered Oct 05 '22 23:10

Will Hartung