Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sending array as a query param in angular post request

I have the following angular post request :

this._http.post(
        RESOURCE_URL, // my query URL
        {
          params : {
            houses: ids
          }
        }
      );

the variable ids is an array of numbers that I send to the back end, with ids = [1,2] for instance.
my issue is, as I send my request, it is sent as the following RESOURCE_URL?houses=1&houses=2, which is not what I want.

I’m trying to have it more like this : RESOURCE_URL?houses=[1,2].

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now one may suggest why I don’t just pass it on to the request body. Problem is, for prject-specific reasons, I cannot. Too much work would be required and I do not have power to decide whether I should dive into it or not.

is there anyway this can be done ? because haveing looked at this topic and also this one, and it seems like it’s just not possible.

>Solution :

It’s possible, it’s just not the way Angular does this. So, just do it manually.

this._http.post('my_url', {
  params: {
    houses: `[${ids.join(',')}]`
  }
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading