Should I put connecting words in my calm api or not?

Let's say I have a controller that takes three parameters:

class Dog {
    function tell (dogId, commandId, rewardId) {
         // blah
    }
}

My url to access this could be:

 mysite.com/dog/tell/1/2/3

In this case, you must remember that the parameters are displayed in dogId, commandIdand rewardIdin that order. Another way to go might be something like:

mysite.com/dog/tell/1/command/2/reward/3

or for even more clarity (but probably more jiggery-pokery with your framework):

mysite.com/tell/dog/1/command/2/reward/3

What's better? Which is more common? At first blushing seems clearer. However, you should still remember what the order of parameters is, and now you must also remember the keywords. ("Was it" dog / team / award "or" team / dog / award "or" dog / in / for "or ...?)

Thoughts? Recommendations? :)

+3
4

, API RESTful. API REST URI , (tell ). , . , API REST HTTP, HTTP- GET, POST, PUT, DELETE ..

, tell, : dog. , , . , :

GET mysite.com/dogs?q=Rover

, URL- , Rover the dog: mysite.com/dogs/3759

Rover the dog:

GET mysite.com/dogs/3739

, , (.. Rover the dog). , , (.. , Rover).

, - Rover, - . , Rover (, Rovers , , Rover , - !). sit Rover:

POST mysite.com/dogs/3739
<command name="sit"/>

- "" () (), (Rover), ( ). POST

Status  : 201 (Created)
Location: mysite.com/dogs/3739/commands/1299

, Rover, ( ). , , URL-, Location. :

GET mysite.com/dogs/3739/commands/1299

. , : (, , , followed=true). , Rover (, ).

, , Rover:

GET mysite.com/dogs/3739

, , , "". , Rover URI:

mysite.com/dogs/3739/commands/

IMO RESTful. , , , . "command" RPC, "" , . "" - , . "" "", , , , , .

, (tl; dr):

  • URI ,
  • / ( ), ( " " )
  • , , , ( ).

RESTful:

http://www.infoq.com/articles/webber-rest-workflow

- "REST in Practice".

, , Fielding ( 5.2 , ):

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

( !), , .

+4

URL-, mysite.com/dog/1/tell, = 2 = 3 POST. , . :

  • , , GET, URL- GET .
  • REST , , URL-. # 1, , , URL- , - .
  • ; HTML- URL- , .
  • - , URL- . , URL-, (1) , , "" "", (2), , URL-. , "" 6 URL-... .
+1

- , , api, , - , api.

0

mysite.com/tell/dog/1/command/2/reward/3

mysite.com/tell?dog=1&command=2&reward=3.

. , . , , , URL-. , , mysite.com/tell/dog/1 - .

Since the dog identifier, team identifier and reward identifier make sense only together, I would indicate this fact and establish the order:

mysite.com/tell/dog-a-command-rewarding-by/1/2/3

or even

mysite.com/tell/dog-a-command-rewarding-by/1-2-3

because you cannot expect mysite.com/tell/dog-a-command-rewarding-by/1to do anything useful either.

0
source

All Articles