0

Is there a way to get specific fields with an Angular $resource? Without creating a new REST endpoint that specifically returns the fields I care about?

For example, let's say I have a Person $resource and it is bound to a REST endpoint where GET returns the full Person object. Is there a way to specify 'select' params (for just _id & names) in addition to the query params? Or do I have to create a PatientNames $resource?

1 Answer 1

1

its all about how you configure your endpoint if you $resources can be parameterized and take key, value pairs to specify query query string params and path based on the url template you used to create the resource ie

  var Person=$resource('/url/person/:id')
  Person.get({fields:['name','ssn']})

this will issue a get request to

  'url/person?fields=name&fields=ssn

now on your server you can take the fields array in the query string and use it to return those fields and if no fields array is present you return them all

Sign up to request clarification or add additional context in comments.

1 Comment

How would you set the fields to use an array syntax in the parameters of the GET request: 'url/person?fields[0]=name&fields[1]=ssn'? PHP doesn't like query parameters with the same name...

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.