New-PSUApiResponse
SYNOPSIS
Returns a custom API response from a PowerShell Universal REST API.
SYNTAX
Body (Default)
New-PSUApiResponse [-StatusCode <Int32>] [-Body <String>] [-Cookies <Hashtable>] [-ContentType <String>]
[-Headers <Hashtable>] [<CommonParameters>]
Data
New-PSUApiResponse [-StatusCode <Int32>] [-Cookies <Hashtable>] [-Data <Byte[]>] [-ContentType <String>]
[-Headers <Hashtable>] [<CommonParameters>]
DESCRIPTION
Returns a custom API response from a PowerShell Universal REST API. This cmdlet should be called within the -Endpoint script block defined in New-PSUEndpoint.
EXAMPLES
Example 1
New-PSUEndpoint -Url '/hello' -Method "GET" -Endpoint {
New-PSUApiResponse -StatusCode 404 -Body "Not found!"
}
Returns a 404 status code from the /hello endpoint when the GET method is called. This is specifying a custom body as well.
PARAMETERS
-Body
The body of the response to send back from the endpoint request.
Type: System.String
Parameter Sets: Body
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-ContentType
The content-type header to set on the response from the endpoint.
Type: System.String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Cookies
A hashtable of cookies to set in the HTTP response.
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Data
Binary data to return from the endpoint. This can be used to send binary files back to the user.
Type: System.Byte[]
Parameter Sets: Data
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-StatusCode
The HTTP status code to set for this response. The default value is 200.
Type: System.Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Headers
A hashtable of headers to return from the API request.
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.