| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Writes an object serialized as BSON to the HTTP response. |
| | 4 | | .DESCRIPTION |
| | 5 | | Converts the provided object to BSON format and writes it to the response body. The status code and content type |
| | 6 | | .PARAMETER InputObject |
| | 7 | | The object to serialize and write to the response. |
| | 8 | | .PARAMETER StatusCode |
| | 9 | | The HTTP status code to set for the response. Defaults to 200. |
| | 10 | | .PARAMETER ContentType |
| | 11 | | The content type to set for the response. If not specified, defaults to application/bson. |
| | 12 | | .EXAMPLE |
| | 13 | | Write-KrBsonResponse -InputObject $myObject -StatusCode 200 -ContentType "application/bson" |
| | 14 | | Writes the $myObject serialized as BSON to the response with a 200 status code and content type "application/bso |
| | 15 | | .NOTES |
| | 16 | | This function is designed to be used in the context of a Kestrun server response. |
| | 17 | | #> |
| | 18 | | function Write-KrBsonResponse { |
| | 19 | | [KestrunRuntimeApi('Route')] |
| | 20 | | [CmdletBinding()] |
| | 21 | | param( |
| | 22 | | [Parameter(Mandatory = $true)] |
| | 23 | | [object]$InputObject, |
| | 24 | | [Parameter()] |
| | 25 | | [int]$StatusCode = 200, |
| | 26 | | [Parameter()] |
| | 27 | | [string]$ContentType |
| | 28 | | ) |
| 0 | 29 | | if ($null -ne $Context.Response) { |
| | 30 | | # Call the C# method on the $Context.Response object |
| 0 | 31 | | $Context.Response.WriteBsonResponse($InputObject, $StatusCode, $ContentType) |
| | 32 | | } |
| | 33 | | } |
| | 34 | |
|