-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Allow Capture of Response Headers with Invoke-RestMethod #4845
Copy link
Copy link
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Problem
Invoke-RestMethodis extremely useful for working with APIs that return parsable objects. My single gripe has been that it is not possible to capture the response headers. Many API's provide (sometimes critical) details via the response headers, especially rate-limiting quotas and session timeouts. In situations where information in the the response headers are required, the user must currently fall back toInvoke-WebRequestand then perform their own Content-Type detection and response-to-object conversion.Proposal
Add a
-ResponseHeadersVariableparameter to the Web Cmdlets that accepts string. this string will be used as the name of a variable in the calling scope. This variable will be set with the same contents ofBasicHtmlWebResponseObject.Headers. The user can then access the variable to retrieve the headers from the previews call toInvoke-RestMethodExample:
This example converts the
Dateresponse header to aDateTime.The functionality would be similar to
-SessionVariable. This would be available for both Web Cmdlets, though it would be redundant onInvoke-WebRequestas it would be a mirror of the returnedHeadersproperty.