0

I have trouble with angular's resource factory. I have path variable id and REST API accepts on same url also query parameter called "id". Let's describe this issue with some example:

Resource url: "/person/:id"

REST API also accepts query param id as filter: "/person?id=5,7,11" or "/person?id=5&id=7&id=11"

$resource("/person/:id", {id: [5, 7, 11]})

This produces invalid url "/person/5,7,11". Did I miss something? I expected that array type cannot be assigned as path variable. Instead it should be converted automatically to query params(?id=5&id=7&id=11). Does anyone have idea how to override this behaviour? Btw. I cannot change name id. Thank you for suggestions..

1
  • remove the /:id and it should work I guess Commented Dec 20, 2016 at 18:53

1 Answer 1

1

Try

$resource('/person/', {'id':[5, 7, 11]}

or, alternatively:

$resource("/person/?id=:myparams", {myparams: [5, 7, 11]})
Sign up to request clarification or add additional context in comments.

2 Comments

I need combination with path variable id. Every object (person in this case) are represented by factory with one unique api path in form "/object/:id". So changing form of url or vars/params in one case out of 10 is not solution for me. I'm looking for generic way.. But thank you
Edit. Sorry. I did not see it first time. Your second tip is probably what I want..with little modification $resource("/person/:id?id=:myparams", {myparams: [5, 7, 11]})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.