-1

Here I want to fetch the multiple IDs from the postman and I'm confuse which method (POST, GET, PUT, DELETE) should I have to use for this. From these IDs I have to retrieve the data from database.

Can I use Get method and using query string then the url will be

localhost:8080/name?ids=1,2,3,4

Can anyone please tell me that I'm thinking is right or not and If not, then What should I have to used for this.

  • Rather than sending all the ids in the query string, have you considered sending them in the `body` and submitting it as a `POST` ? Since, you're going to be querying the database with those `ids`, I would prefer sending them in the body, and it won't expose them in the URL. You could make it look like `localhost:8080/names`, in the **request body** - `{"user_ids": [1, 2, 3, 4]}` – Kedarnag Mukanahallipatna Sep 12 '18 at 04:33
  • 1
    @KedarnagMukanahallipatna I don't I don't think that there is post method is used because we are getting the records. –  Sep 12 '18 at 04:44
  • `POST` is meant to store something and `GET` is to retrieve, however, `POST` is more secure in a way where _request payload is not logged by the server_. – Kedarnag Mukanahallipatna Sep 12 '18 at 04:51
  • @KedarnagMukanahallipatna But here I want to retrieve the records sir thats why I'm telling this –  Sep 12 '18 at 04:52
  • 1
    Possible duplicate of [How to construct a REST API that takes an array of id's for the resources](https://stackoverflow.com/questions/4541338/how-to-construct-a-rest-api-that-takes-an-array-of-ids-for-the-resources) – avenged_badger Sep 12 '18 at 10:06

1 Answers1

1

Surely you can do it GET method. And it depends on how you are dealing with the ids, the best way to do it would be sending the values as an array. Something like this

localhost:8080/name?ids=[1,2,3,4] Then you can retrieve that ids with something like this:

ids := r.URL.Query().Get("ids")
log.Println(ids)

And you will get the data like this [1,2,3,3], but again it depends on how you are dealing with the data.

monirz
  • 534
  • 5
  • 14