18

I am designing RESTful Api's and would like some advice on designing an API where the caller wants to query records based on more than one search parameter.

I have only seen restful apis that use one parameter.

how should i do this?

e.g. if i have created a restful api for a list of contacts, how would I format a call that returned all contacts with firstname==bob & surname==smith?

I guess it should be a GET because I am retrieving?

My only thoughts are:

http://api.myapi.com/contacts/firstname/bob&surname=smith

But that doesn't seem right ;-(

Please advice.

Also, do any of the php frameworks support this? e.g. symfony, konstrukt etc.

streetparade
  • 32,000
  • 37
  • 101
  • 123
DEzra
  • 2,978
  • 5
  • 31
  • 50

1 Answers1

24

I think

http://api.myapi.com/contacts?firstname=bob&surname=smith

is the way to go if you have a set of parameters, all of which are optional.

Matti Virkkunen
  • 63,558
  • 9
  • 127
  • 159
  • 2
    I agree; it is called the "query" string – rojoca Apr 14 '10 at 20:07
  • 2
    yes, i like this. I guess by Query string u mean: $_SERVER['QUERY_STRING'] contains firstname=bob&surname=smith. or: $_GET['firstname'] is better - less parsing needed. http://ditio.net/2008/06/12/php-query-string/ – DEzra Apr 14 '10 at 21:28
  • you could even loop through $_GET to build the query – Galen Apr 15 '10 at 18:38