I am using Angular with SilverStripe for my backend. I am using this module https://github.com/silverstripe/silverstripe-restfulserver for my REST API instead of building it myself.
When the API returns a list with a many_many relationship it looks like
<Recipe href="http://localhost/groceryList/api/v1/Recipe/2.xml">
<Title>Chilli</Title>
<ID>2</ID>
<Ingredients linktype="many_many" href="http://localhost/groceryList/api/v1/Recipe/2/Ingredients.xml">
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/5.xml" id="5"/>
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/6.xml" id="6"/>
<Ingredient href="http://localhost/groceryList/api/v1/Ingredient/7.xml" id="7"/>
</Ingredients>
</Recipe>
My question is 2 part.
Why is the collection of ingredients a bunch of links? I was hoping it would contain the name of each ingredient. Is this how REST is suppose to work?
Using Angular $Resource, how can easily get the ingredients to loop through using ng-repeat?
First you need to convert your XML to JSON with https://code.google.com/p/x2js/ or https://github.com/johngeorgewright/angular-xml, so you need an HttpInterceptor to convert all your requests and responses from the server.
I don't know why you don't have the name of each ingredient into your response, I think you need to change the response returned by your API, but I don't know how SilverStripe work.