Jump to content

Best Api Practice


monkeypaw201

Recommended Posts

Hello,

 

I am in the processing of building out an API for a web service and ran into some debates (surprise, surprise...) about the best way for API parameters to be passed.

 

Option 1:

domain/service/method/key=value&key2=value2

 

Option 2:

domain/service/method/key/value/key2/value

 

Option 3:

domain/service/method?key=value&key2=value2

 

Option 4:

domain/service/method/key=value/key=value

 

I know it may seem petty, but I'd like the community's feedback (including if its none of the above and something else!)

 

Thanks!

Edited by monkeypaw201
Link to comment
Share on other sites

1 and 3 are virtually identical, as are 2 and 4.

 

As a developer I don't want to have to force key/value pairs into some custom URL structure. I want to write code like

$data = array(
   "key" => "value",
   "key2" => "value2"
);
$url = "http colon slash slash www.example.com/service/method?" . http_build_query($data);

(or cURL if I have to POST stuff). In other words, conform to existing standards and use existing functions and methodologies.

 

URL rewriting is primarily for users so they can see a pretty and memorable address in their browser and in the links they click. That does not apply to an API.

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.