Google Groups

Re: How to handle a list when the query param string is too long for a GET request

mikeschinkel2 Apr 9, 2012 10:02 AM
Posted in group: API Craft
On Apr 9, 2012, at 12:51 PM, guivalerio wrote:
I am implementing an API method that should receive a list of facebook
IDs (e.g. 123,345,765,234) and return all users who have those IDs
linked to their account.

Initially I was using the users list method, which is also used when
running a search by name (i.e. /users?q=john+smith), but the facebook
IDs param can be reaaally long, as it will contain all the user's
friends IDs.

So there is my problem. A request on /users?facebook_ids={massive long
string with comma separated IDs} will break on a GET, so I need to
pass it via a POST.

I don't really want to use a POST request on /users, as that is for
creating a new user. For now I have made a temporary hack so it works
under something like /facebookfriends via a POST, which is horrible.

So the call returns a list and although it should be done via a GET
method, I can't, as the string with the list of facebook IDs is
massive. No really sure the best way forward.

Did anyone have any similar situation? How did you handle it?

Agree, it's not ideal, nor is my suggestion. But this is one way to handle:

1.) POST the list of users to create a "user list" (a noun). Return 201 "Created" with a "Location" header to a URL like /userlists/{$userlist_id}

2.) GET /userlists/{$userlist_id} to retrieve the list of users.

3.) Also support DELETE /userlists/{$userlist_id} to explicitly purge the list.

4.) Optionally delete a user list after a length of time since last accessed (1 hour, 1 day, 30 days?), assuming no system would ever need to "bookmark" the list.

Hope this helps?