monkeypaw201 Posted September 26, 2012 Share Posted September 26, 2012 (edited) 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 September 26, 2012 by monkeypaw201 Quote Link to comment https://forums.phpfreaks.com/topic/268835-best-api-practice/ Share on other sites More sharing options...
requinix Posted September 26, 2012 Share Posted September 26, 2012 (edited) 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 September 26, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/268835-best-api-practice/#findComment-1381221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.