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!

Link to comment
https://forums.phpfreaks.com/topic/268835-best-api-practice/
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.

Link to comment
https://forums.phpfreaks.com/topic/268835-best-api-practice/#findComment-1381221
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.