0

I am writing a RESTful API specification and there's an API that needs a bunch of input data to do a query and return some results. It behaves like a GET because you're just asking for information, but because you need to provide a bunch of request data, it seems like it should a POST.

Any thoughts?

Thanks!

mstrom
  • 1,655
  • 3
  • 26
  • 41
  • 1
    Possible duplicate of http://stackoverflow.com/questions/5020704/how-to-design-restful-search-filtering – rangalo Jun 27 '14 at 12:55
  • Please describe in more detail what the "bunch of input data" is and how it is used to perform the query. Do they filter the result? –  Jun 27 '14 at 14:40
  • It's a bunch of data that the API will use to do a search and say if there were any matching results. – mstrom Jun 27 '14 at 16:35

2 Answers2

1

If you want to send a form then use POST. It may be easier to handle it in eventual HTTP clients.

I usually use GET if I want to keep my query parameters in URL, so it could be copied and used somewhere else and executed with the same result.

Piotr Krysiak
  • 2,815
  • 3
  • 23
  • 35
1

If you are trying to create a "RESTful" API, then you should conform to the typical conventions for HTTP methods:

  • GET - List/retrieve item or collection (safe to call without changes)
  • POST - Create/insert a new entry or collection (will change data)
  • PUT - Replace/update an entry or collection (will change data, but can be called multiple times safely)
  • DELETE - delete item or collection

So even if you have 50 parameters for your query, use HTTP GET.

For developers using the RESTful style, these are the assumed behaviors-- if they see POST, they will assume you are inserting a record or records.

Wikipedia entry has a little table which you can print and tape on your wall: https://en.wikipedia.org/wiki/Representational_State_Transfer

Raul Nohea Goodness
  • 2,549
  • 23
  • 24