1

I'm pushed into a peculiar situation where I'm not able to decide what is wrong and what is right.

I've a resource called Invoice. To get a JSON or XML representation I use below URI

somedomain.com/inovices/{InvoiceNumber} - Invoice number is numeric Accept: application/xml 

When I want a PDF of same resource I use below URI:

somedomain.com/inovices/{InvoiceNumber} - Invoice number is numeric Accept: application/pdf 

Both the above url's are served for authenticated requests. We also want to support same resource using a GUID for unauthenticated requests, hence we want to use below URL

somedomain.com/inovices/{GUID} Accept: application/pdf 

Above URL is like a permanent URL and anybody can access this URL any number of times. My confusion is whether providing URL as above is RESTful or not. Because in one URL I'm using invoice number which is numeric and for permanent URL I'm replacing it with GUID.

Reason why I felt this is wrong is same resource is represented with two different URI's (number and GUID) even though they are returning same resource. Or is it just my assumption that it is wrong? Is it against any REST cosntraint is what I'm not able to understand?

3
  • Surely you can deliver the same document using different URLs. Why shouldn't it be allowed? I have seen it multiple times in real-world applications and I don't see any logical reason why it should be wrong. Commented May 19, 2013 at 18:03
  • @dirkk Thanks for the confirmation, can you point me to some URL's if you remember? Commented May 19, 2013 at 18:09
  • Sorry, they were internal customer projects. Can't do that. Commented May 19, 2013 at 18:13

1 Answer 1

2

There's no problem at all different URIs to point at the same resource. It's not only ok, sometimes it's also recommended, if that would add value to the user.

Think of these examples:

GET /api/users/543 GET /api/users/bob-marley 

or, as SO does:

GET /questions/16637720/restful-different-uri-of-same-resource-to-get-different-forms-of-same-resource GET /q/16637720/1118323 

There are similar examples everywhere. You may want to add this "unnessecary" information if it's going to help users, or SEO, and still keep the short version available. Or imagine senarios, where you would want to add more ways of accessing resources without breaking existing ones. It sounds quite common to me and you don't break any rules by having more than one URI for the same resource.

If you are worried that a user might think that the two resources are different since she used different URI, you can have one URI redirect to the other, to make it explicit that it's exactly the same resource (as SO does when you hit the short link, or the link without the thread heading).

Here is a relevant answer.

Sign up to request clarification or add additional context in comments.

1 Comment

What would happen if you tried to do a PUT against the "alias/simple" URI to create it? PUT can be used to create a resource as long as the resource path is known by the client and respected during the creation right... but with the "aliases" version, the PUT result would not be a redirect right?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.