0

I'm trying to understand how to construct URIs for RESTful web services. Assume I had a dating site, would the following be correct:

  • domain.com/profiles/ <-- list of profiles
  • domain.com/profiles/123/ <-- profile number 123
  • domain.com/profiles/123/likes/ <-- list of profile 123's likes
  • domain.com/profiles/123/likes/2/ <-- 2nd item in the list of profile 123's likes

Am I close or did I get this totally wrong?

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
  • http://stackoverflow.com/questions/4003665/uri-for-restful-web-services – StackOverflowNewbie Oct 23 '10 at 11:42
  • 1
    I found the following post helpful when I was in your spot: http://stackoverflow.com/questions/2001773/understanding-rest-verbs-error-codes-and-authentication/2025116#2025116. Focus on defining the resource(s) well; the URLs should come for free after that. – Roatin Marth Oct 23 '10 at 11:46
  • What your URIs look like doesn't matter. There are no URIs that are more 'restful' than others. There is no such thing as a 'restful' URI. Nothing about how your URIs look makes your service satisfy the conditions of REST. – rojoca Oct 23 '10 at 14:27

2 Answers2

2

Just think about whether your URLs provide meaningful operations for GET, POST, PUT and DELETE requests. That's what REST is really about, rather than beautiful URLs.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
0

Looks like you are trying to slip method chaining into here. If you are using a framework, your method may end up looking like this:

 function profiles($pid=0,$likes=0,$which=0){} 

which can be more difficult to program.

when you may really be going for:

 function listProfiles(){}
 function getProfile($profileID){}
 function getLikes($profileID){}
 function getLikeElement($profileID,$int){}

This being said, your implementation is entirely up to you. There is no one standard.

Brandon Frohbieter
  • 17,563
  • 3
  • 40
  • 62