문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top