Skip to content

Invoke-RestMethod & Invoke-WebRequest should have tab completion for -ContentType #24917

@ArmaanMcleod

Description

@ArmaanMcleod

Summary of the new feature / enhancement

As a user who tests API REST calls from the terminal using Invoke-RestMethod & Invoke-WebRequest frequently, it would be very beneficial to have tab completion for content types. Especially for common ones like application/json or application/x-www-form-urlencoded which can get cumbersome to type out every time.

Given the list of MIME Types is quite big and most of these are not commonly used in PowerShell, we could limit tab completion to common content types.

Quick grep search of content types across GitHub repos for PowerShell:

  • application/json
  • application/x-www-form-urlencoded
  • application/xml
  • application/zip
  • application/octet-stream

We could even use .NET Media MIME types in System.Net.Mime.MediaTypeNames to load these in dynamically and avoid hardcoding a list.

It would improve the developer experience of these cmdlets, especially when testing API calls.

Proposed technical implementation details (optional)

  • Add a ContentArgumentCompleter to virtual property ContentType in WebRequestPSCmdlet base class.
  • Ensure user can do something like Invoke-RestMethod -ContentType <TAB> and cycle through completions of content types.
  • If they provide start of word it would complete the possible content type completions e.g. Invoke-RestMethod -ContentType 'app<TAB> would complete to Invoke-RestMethod -ContentType 'application/json'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions