< Summary - Kestrun — Combined Coverage

Information
Class: Public.Request.Get-KrRequestBody
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Request/Get-KrRequestBody.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 61
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 14:53:17 Line coverage: 0% (0/2) Total lines: 23 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743109/01/2025 - 04:08:24 Line coverage: 0% (0/9) Total lines: 50 Tag: Kestrun/Kestrun@d6f26a131219b7a7fcb4e129af3193ec2ec4892909/04/2025 - 18:11:31 Line coverage: 0% (0/9) Total lines: 51 Tag: Kestrun/Kestrun@de99e24698289f3f61ac7b73e96092732ae12b0512/12/2025 - 17:27:19 Line coverage: 0% (0/12) Total lines: 61 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Request/Get-KrRequestBody.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Retrieves a request body value from the HTTP request.
 4    .DESCRIPTION
 5        This function accesses the current HTTP request context and retrieves the value
 6        of the request body.
 7    .PARAMETER Raw
 8        If specified, retrieves the raw request body without any parsing.
 9    .PARAMETER Type
 10        Specifies the type to which the request body should be deserialized.
 11    .EXAMPLE
 12        $value = Get-KrRequestBody
 13        Retrieves the value of the request body from the HTTP request.
 14    .EXAMPLE
 15        $value = Get-KrRequestBody -Raw
 16        Retrieves the raw request body from the HTTP request without any parsing.
 17    .OUTPUTS
 18        Returns the value of the request body, or $null if not found.
 19    .NOTES
 20        This function is designed to be used in the context of a Kestrun server response.
 21#>
 22function Get-KrRequestBody {
 23    [KestrunRuntimeApi('Route')]
 24    [CmdletBinding()]
 25    [OutputType([Hashtable])]
 26    param(
 27        [switch]$Raw,
 28        [Type]$Type
 29    )
 30
 031    if ($null -ne $Context.Request) {
 032        $body = $Context.Request.Body
 33        # Return the raw body if specified
 034        if ($Raw) {
 35            # Get the raw request body value from the request
 036            return $body
 37        }
 38        # Parse the request body based on the specified type or content type
 039        if ($null -ne $Type) {
 040            return [Kestrun.Utilities.Json.JsonSerializerHelper]::FromJson($body, $Type)
 41        }
 42        # Parse based on Content-Type
 043        switch ($Context.Request.ContentType) {
 44            'application/json' {
 045                return $body | ConvertFrom-Json -AsHashtable
 46            }
 47            'application/yaml' {
 048                return [Kestrun.Utilities.YamlHelper]::ToHashtable( $body)
 49            }
 50            'application/x-www-form-urlencoded' {
 051                return $Context.Request.Form
 52            }
 53            'application/xml' {
 054                return [Kestrun.Utilities.XmlHelper]::ToHashtable( $body)
 55            }
 56            default {
 057                return $body
 58            }
 59        }
 60    }
 61}

Methods/Properties

Get-KrRequestBody()