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.

Also include next and totalResources for nested resources.

See original GitHub issue

Is your feature request related to a problem? Please describe. Retrieving a set of date entities returns, for example with:

  • api/v1/devices

Results in next links and total resources.

{
meta: {
  totalResources: 3
},
links: {
  self: "/api/v1/devices?page[size]=2",
  first: "/api/v1/devices?page[size]=2",
  last: "/api/v1/devices?page[size]=2&page[number]=2",
  next: "/api/v1/devices?page[size]=2&page[number]=2"
},
data: [...

However, when calling a nested endpoint which contains a list of data entities such as:

  • api/v1/locations/<id>/devices

It seems that totalResources as well as the next link is not included in the result which makes it hard for the client to paginate. Pagination works (the query parameters can be used) but the links and information of the total number of resources is omitted in the json result.

{
links: {
  self: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices",
  first: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices"
},
  data: [...
{

We have noticed that there is no count query executed for these kind of URIs which might indicate that this is intended and therefore I didn’t log it as a bug.

Describe the solution you’d like Results in nested results that are consistent with an entity list that is retrieve via the direct devices call. A next link probably is definitely desired since there is a prev link if you would would grab a page further in the order:

{
links: {
  self: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1&page[number]=2",
  first: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1",
  prev: "/api/v1/locations/008b34d8-7dfe-40f1-a422-3bff500744b8/devices?page[size]=1"
},
data: [...

So it feels inconsistent that you can use the links to get the prev yet have to construct the next links yourself. The totalResources would definitely be convenient as well since it’s more consistent to the other results.

Describe alternatives you’ve considered Currently we will postprocess the json result and add the information ourselves, if there is a better solution, please advise.

Additional context Version 4.2.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
databrechtcommented, Dec 23, 2021

Only got to it now, I upgraded to the latest version to test (5.0.0-pre1). It works now, my case is solved and I can remove my workarounds, thanks!

0reactions
databrechtcommented, Nov 8, 2021

That’s awesome, I’ll look into it. However, at least this week I’m working on a deadline of another project. Once I have some time for the other project I’ll test it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are best practices for REST nested resources?
I've tried both design strategies - nested and non-nested endpoints. I've found that: if the nested resource has a primary key and you...
Read more >
REST API Design Best Practices for Sub and Nested ...
Many questions arise when we start designing an API, especially if we want to create a REST API and adhere to the REST...
Read more >
REST API: POST and PUT for nested resources
For example, I have a REST API with Persons and their Cars. So "cars" is a nested array of a Person. Also of...
Read more >
RESTful & Nested Resources
On to nested resources! What does REST have to do with nested resources, you say? Why do you care? Let's define a nested...
Read more >
How To Create Nested Resources for a Ruby on Rails ...
In this tutorial, you will build on an existing Rails application that offers users facts about sharks. This application already has a model...
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