question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Restangularize subresources

See original GitHub issue

Is there a simple way to tell restangular that a certain field is a collection of resources?

For instance in my app I can do:

GET to: /api/courses/123
Restangular.one('courses', 123).get();

/* OR */

GET to: /api/courses/123/students
Restangular.one('courses', 123).all('students').getList();

The first call however, fetches the course with a field students that already contains an array of the students in the course. Is there any way to say: “Restangular, this array is not merely an array of objects, but rather it’s a student collection” so that then I can do things like students[0].remove()

Unrelated: Vamos a ganar el mundial o no?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pauldijoucommented, Jul 1, 2014

What about:

Restangular.one('courses', 123).get().then(function (course) {
  course.students = Restangular.restangularizeCollection(course, course.students, 'students');
  // You should now be able to do 'course.students[0].remove()'
  // And if you want to chain promises:
  return course;
});
0reactions
daviesgeekcommented, Aug 31, 2016

Can a more concrete example be provided for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining sub-resources for your RESTful API - Medium
Article 10 in the series of “ Pragmatic decisions for your RESTful API”, this post talks about defining sub-resources in your RESTful API....
Read more >
RESTful design: when to use sub-resources? - Stack Overflow
Assign all resources a canonical URI at the root (e.g. /companies/{id} and /employees/{id} ). If a resource cannot exist without another, it should...
Read more >
REST API Design Best Practices for Sub and Nested Resources
One topic in this space that is debated quite often is the nesting of resources also called sub-resources. Why would anyone nest their...
Read more >
REST Web Services 25 - Implementing Subresources - YouTube
Website: http://javabrains.koushik.org/courses/javaee_jaxrs/lessons/Implementing-SubresourcesWe'll now implement nested resources using the ...
Read more >
REST API - Handling subresources
Would it be incorrect to consider profile,address,contacts as subresources. No, anything you like can be a subresource. REST doesn't care (a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found