You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invoke-RestMethod -FollowRelLink should return a single array of objects #5526
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-Cmdletsgeneral cmdlet issues
Invoke-RestMethod with the -FollowRelLink parameter correctly retrieves additional pages of results from REST services. However, the return is an array of pages rather than one array of all results.
Thanks, Mark Kraus (@markekraus). You're absolutely right that the current behavior more closely matches the actual return. However, from my (outside) perspective FollowRelLink was added as a convenience so the caller doesn't need to think about paging and multiple calls. With that spirit in mind it seems like we shouldn't require them to post-process results in any way either.
dddugan It's certainly a difference of opinion on how it should work. On the one hand, we need to maintain parity with the objects as they are returned from the API and on the other is convenience. I cannot condone making the default behavior break parity with APIs. As someone who works heavily with APIs, I cannot stand it when something makes assumptions about how the objects should be provided to me, especially when that assumption breaks with what the API has documented. The API says it will return an array of objects per page, I would expect and array of arrays from FollowReLlink. My vehicle for obtaining these objects from the API may change, and I don't want to adjust my logic to fit with what ever API breaking format that vehicle has decided to impose on me.
We could maybe add a switch to unwrap arrays, but, I'm not real excited about doing so. I think it is best to just return the objects as they are and let the user decide how they want to process them.
FollowRelLink was added as a convenience so the caller doesn't need to think about paging and multiple calls.
And they don't. In 5.1 for this operation to work you needed
fall back to Invoke-WebRequest,
Check for errors,
Inspect Content-type header,
convert the Content to an object,
handle serialization errors,
inspect the headers for Link,
regex parse the single Link header,
and finally repeat the process with the next link URI.
In 6.0.0 irm -FollowRelLink manages all of that for you.
dddugan nothing from my end. I think this might make sense to note this in the documentation. If that wasn't what you expected, it's likely others will possible have the same experience.
Will do Rain Sallow (/u/ta11ow) (@vexx32) . For now I will use the DIY version for V5 of Powershell so I can get my job done ,then i'll come back and log it :)
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-Cmdletsgeneral cmdlet issues
Activity
dddugan commentedon Nov 22, 2017
The specific API I'm using returns multiple Link headers, which may or may not be related.
#5265
markekraus commentedon Nov 22, 2017
I disagree. If we do this we lose parity with the JSON objects being returned from the APIs.
Page 1
[ { "Value": "One", "Id": 1 }, { "Value": "Two", "Id": 2 } ]Page 2:
[ { "Value": "Three", "Id": 3 }, { "Value": "Four", "Id": 4 } ]That is clearly 2 JSON arrays of JSON objects, not a single array of objects.
markekraus commentedon Nov 22, 2017
#5265 is unrelated to the output.
markekraus commentedon Nov 22, 2017
I will also add that unwrapping the jagged array is easily done with
Foreach-Object:Count : 2
Count: 60.
dddugan commentedon Nov 22, 2017
Thanks, Mark Kraus (@markekraus). You're absolutely right that the current behavior more closely matches the actual return. However, from my (outside) perspective FollowRelLink was added as a convenience so the caller doesn't need to think about paging and multiple calls. With that spirit in mind it seems like we shouldn't require them to post-process results in any way either.
markekraus commentedon Nov 22, 2017
dddugan It's certainly a difference of opinion on how it should work. On the one hand, we need to maintain parity with the objects as they are returned from the API and on the other is convenience. I cannot condone making the default behavior break parity with APIs. As someone who works heavily with APIs, I cannot stand it when something makes assumptions about how the objects should be provided to me, especially when that assumption breaks with what the API has documented. The API says it will return an array of objects per page, I would expect and array of arrays from
FollowReLlink. My vehicle for obtaining these objects from the API may change, and I don't want to adjust my logic to fit with what ever API breaking format that vehicle has decided to impose on me.We could maybe add a switch to unwrap arrays, but, I'm not real excited about doing so. I think it is best to just return the objects as they are and let the user decide how they want to process them.
And they don't. In 5.1 for this operation to work you needed
Invoke-WebRequest,Contentto an object,Link,Linkheader,nextlink URI.In 6.0.0
irm -FollowRelLinkmanages all of that for you.jmiller76 commentedon Nov 22, 2017
Mark Kraus (@markekraus) I second that. It is easy to merge the multiple pages in script, but not trivial to unwind it if merged in cmdlet.
Unless there is a particular efficiency gain from append them in the cmdlet that is.
Does the project have any specific single responsibility type guidance for things like this?
markekraus commentedon Nov 22, 2017
Good question. I don't know about any in the project specifically, There is always the "The PowerShell Best Practices and Style Guide" (One relvant to this thread)
dddugan commentedon Nov 28, 2017
Fair enough. Given:
I see the logic in status quo. It just wasn't the behavior I originally expected, which prompted me to raise the issue prior to GA.
Any further discussion before we close this?
markekraus commentedon Nov 28, 2017
dddugan nothing from my end. I think this might make sense to note this in the documentation. If that wasn't what you expected, it's likely others will possible have the same experience.
Collapse the jagged array returned by FollowRelLink
silentdth commentedon Sep 7, 2020
Just a note here - in PS 7.10 preview 6 the
FollowRelLinkdoesn't work at all. You only get the first page.vexx32 commentedon Sep 7, 2020
silentdth you should probably file a new issue for that so it can be triaged appropriately, assuming there isn't an open issue for it yet. 🙂
silentdth commentedon Sep 7, 2020
Will do Rain Sallow (/u/ta11ow) (@vexx32) . For now I will use the DIY version for V5 of Powershell so I can get my job done ,then i'll come back and log it :)