0

I am building an app for finding meetings close to a given location.

I want to send latlng coordinates and a radius to an API which will return a list of meetings within the radius of the given coordinates.

{
  origin: {
    lat: 2.1,
    lng: 1
  },
  radius: 5
}

What HTTP verb should I use? It's not clear from this list what I should use?

Vinyl Warmth
  • 2,226
  • 3
  • 25
  • 50

3 Answers3

3

As you retrieve data from the API, you should use GET. (the latitude and longitude are filters for the APIs)

Bohus Andrei
  • 328
  • 3
  • 7
  • The issue with GET is that he has a payload that seems to be more complex than simply pushing it on the URI. – Sean Murphy Jan 19 '19 at 19:28
  • There are plenty of ways it could be serialized to a URL. PHP style: `foo?origin[lat]=2.1&origin[lng]=1&radius=5`, encoded JSON: `foo?json=%7B%22origin%22%3A%7B%22lat%22%3A2.1%2C%22lng%22%3A1%7D%2C%22radius%22%3A5%7D`, etc. – Quentin Jan 19 '19 at 19:30
  • What happens with the use-case evolves? Say he wants to get meeting within a radius of certain coordinates that start/end on specific date times, and filter for meetings with specific titles or content? This could very quickly evolve into something that requires an actual body content and not just something that could be serialized on the URI as it would start exceeding the 2000 char defacto length limit. – Sean Murphy Jan 19 '19 at 19:32
  • 2
    Using the wrong tool for the job on the off chance that, in the future, the right tool is no longer suitable is a ridiculous idea. – Quentin Jan 19 '19 at 19:38
  • Architecting a solution with no thoughts toward scalability is equally ridiculous. – Sean Murphy Jan 19 '19 at 19:39
  • 1
    Remember a Get request with query params will work nice with history / back/fwd, etc. POST / Body will break this. – Keith Jan 19 '19 at 19:43
  • back/fwd with an ajax type of request? Perhaps an assumption on my part - but I don't think the API is being browsed directly here. – Sean Murphy Jan 19 '19 at 19:52
  • For the problem regarding URI length I will use a so called 'batch'(HTTP multipart request) call. Which will contain only on GET request which might exceed the 2000 characters . Batch are sent using POST. In this way you fix the technical limitation but you also respect the RESTful programming model show the actual intention of your API (getting data). – Bohus Andrei Jan 19 '19 at 19:54
1

I would simply use POST for this operation. Don't get overly pedantic thinking about which verbs correspond to which kinds of operations in a RESTful sense. Traditionally POSTs are to create an object - but in this situation, Occam's Razor applies - typically the simplest solution is the correct one.

If you want to use GET, refactor your request to put the parameters on the URI. A payload body in a GET request is not standard.

Additionally please see this SO: How to design RESTful search/filtering?

This question is largely a religious/opinion-based discussion. The SO referenced above denotes the search itself as being a resource, and also correctly points out that mere use of a POST alone doesn't necessarily require that something be created in a database somewhere.

Sean Murphy
  • 516
  • 4
  • 7
-2

There is no definite answer to the opinion-based question. I will use a query string to send JSON parameters over HTTP Get.

tuggo
  • 23
  • 7