tags:

views:

268

answers:

2

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.

+5  A: 

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
I agree; it is called the "query" string
rojoca
DEzra
you could even loop through $_GET to build the query
Galen
A: 

The Magic Word is "Reflection" Read this tutorial how piwik automaticaly generates The API

http://piwik.org/blog/2009/02/software-geeks-how-piwik-automatically-generates-the-api-using-php-reflection/

streetparade
I don't think this addresses the question very well. The OP is asking about URLs, but you've provided a link to a framework that does automatic API generation, and for an API that's horribly not RESTful as well.
Rob Hruska