Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow Capture of Response Headers with Invoke-RestMethod #4845

Copy link
Copy link
@markekraus

Description

@markekraus
Issue body actions

Problem

Invoke-RestMethod is 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 to Invoke-WebRequest and then perform their own Content-Type detection and response-to-object conversion.

Proposal

Add a -ResponseHeadersVariable parameter 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 of BasicHtmlWebResponseObject.Headers. The user can then access the variable to retrieve the headers from the previews call to Invoke-RestMethod

Example:

$GetData = Invoke-RestMethod -Uri 'http://localhost:8083/Get/' -ResponseHeadersVariable 'ResonseHeaders'
$ResponseDate = [DateTime]$ResonseHeaders.Date[0]

This example converts the Date response header to a DateTime.

The functionality would be similar to -SessionVariable. This would be available for both Web Cmdlets, though it would be redundant on Invoke-WebRequest as it would be a mirror of the returned Headers property.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.