0

I have the following functionalities in my API:

  • Getting a user by their name
  • Getting a user by their ID
  • Getting a user, or if it doesn't exist create one
  • Getting multiple users by their ID

Currently I'm handling the two first functionalities with a GET request, and the third with a POST request. I could use a GET request for getting multiple users, but sending potentially hundreds of IDs through a query parameter seems like the wrong approach, as I would get a very long URL. I could also use a POST request to send the long list of IDs through its body, but I doubt a POST request is meant for this purpose.

What method would be appropriate to use for the last one?

Ferskfisk
  • 13
  • 1
  • 5
  • If you expect to pass a very long list of IDs, you can consider [this](https://stackoverflow.com/a/33946754/1073758) approach. – moonwave99 Mar 21 '22 at 21:06
  • `but I doubt a POST request is meant for this purpose.` why not? A `POST` does not need to create a resource, it can return `200` to indicate that the `POST` was successful with some information returned. `204` if the `POST` was successful with no body. Or `201` if the resource was created. You could send the result of the query along with the `200`, or create an actual result resource `201` that you could obtain with an additional `GET`request, and `DELETE` if it is not needed anymore. – t.niese Mar 21 '22 at 21:54

1 Answers1

0

I see 2 possible ways here:

  1. Get all users and do your filtering post response.
  2. Get a range of IDs, which resumes to only 2 parameters, the lower and the upper limits of the interval. (If this satisfy your needs)

Behaving the way you described and avoiding long URLs in the same time will not work together.

paul.radu
  • 56
  • 3