-1

I'm looking to add search functionality to an API, on a resource called Organizations. Organizations can have different Location and Audience ids tagged onto them (which I would like to use in searching). Since these ids are MongoDB ObjectIds, they are quite long and I'm worried about reaching the max query string limit of the browser with a GET request. For example:

GET http://my-site.com/api/organizations?locations=5afa54e5516c5b57c0d43227,5afa54e5516c5b57c0d43226,5afa54e5516c5b57c0d43225,5afa54e5516c5b57c0d43224&audiences=5afa54e5516c5b57c0d43223,5afa54e5516c5b57c0d43222

Which would probably be about an average search, however I don't want it to break if users select many Locations or Audiences.

Any advice on how I could handle this situation?

  • Put the list in the "body" of a different request type instead of GET? It's not really clear based on the question content what you really want to do, but typically instead of sending a "list" you probably should be looking at storing a common "singular" Id value which will be shared amongst what you actually get to retrieve. Better to give content on what you need to achieve than ask what is essentially a very broad question. – Neil Lunn May 23 '18 at 01:04
  • Looks to me like there is no serious limit: https://stackoverflow.com/questions/812925/what-is-the-maximum-possible-length-of-a-query-string – Robert Moskal May 23 '18 at 01:17

1 Answers1

0

I've ran into your situation before. You can change your method to POST

For a input of locations and audiences, your resource is not already sitting there. You have to compute it.

By the definition of POST:

Perform resource-specific processing on the request payload.

Providing a block of data, such as the fields entered into an HTML form, to a data-handling process;

You have to compute and create new resource for response. So it's REST-compliance to do so.

Community
  • 1
  • 1
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51