Pregunta

I am implementing an HTTP REST API which contains a /feed request. The request returns a user's news feed.

The request comes with a few parameters, including the userId, a list of followers, startTime and maxItems.

The easiest way to implement it on the server side (Python and Flask) would be adding a JSON payload, from which I can read the arguments.

Alas, adding a payload to a GET request is not a good idea, and it is no supported by many client libraries.

My options:

  • Making /feed a POST request. It is ugly, because POST shouldn't be used to request information from a server.
  • Splitting the /feed call to /updateFollowers (POST) and /feed (GET). It would waste time because the GET call can be made only after the POST call.

Both options seem wrong. Is there any standard way to make a GET-like call with a bunch of complex arguments?

¿Fue útil?

Solución

Splitting the /feed call to /updateFollowers (POST) and /feed (GET). It would waste time because the GET call can be made only after the POST call.

REST doesn't really have rules as you are probably aware but I'd like to share my opinion with you: It's quite ugly to put 'request type verbs' in the resource like this, so I wouldn't do this.

Making /feed a POST request. It is ugly, because POST shouldn't be used to request information from a server.

I understand why you think this is ugly. It sounds wrong to get data using a POST request, however, as stated in this question's top answer:

The best way to implement a RESTful search is to consider the search itself to be a resource. Then you can use the POST verb because you are creating a search. You do not have to literally create something in a database in order to use a POST.

Since this is similiar to what you're doing, using POST might not be such a bad idea. I don't see a better alternative so you probably want to implement it like this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top