PowerShell / PowerShell/PowerShell

`Invoke-RestMethod` & `Invoke-WebRequest` should have tab completion for `-ContentType`

Open
#24,917 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In-PR Issue-Enhancement Needs-Triage WG-Cmdlets
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

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'.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WebRequestPSCmdlet base class and its virtual ContentType property, then review how argument completers are implemented for PowerShell cmdlets. Add completion for common content types for both Invoke-RestMethod and Invoke-WebRequest, including prefix matching such as “app”, and verify that cycling through completions works.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli, developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.