I have a resource in my API called /foos
. I can create a new Foo by making a POST
request to this URL.
In the client I use Angular's ngResource
to deal with API calls. Insertion is easy:
var newFoo = new Foo({param1: 'value1'});
newFoo.$save();
So far, so good. The API returns the following:
{id: 1, param1: "value1"}
Now, here's the good part. For the sake of simplicity my API allows to specify which related entities should be returned in the response by means of a query string param, with
. So:
GET /foos/1?with=relatedEntity
Would return
{id: 1, param1: "value1", relatedEntity: { ... }}
This is also accepted in POST
requests. I'd like to create a Foo and have it returned back with some related entities so that I can use them straight away in my app without the need to perform another request:
POST /foos?with=relatedEntity
However, I've been unable to achieve this using standard the ngResource $save()
function.
Can this be done at all?