< Back

Add-PodeRoute

Sat Jan 18, 2020 7:13 pm

NAME Add-PodeRoute



SYNOPSIS

Adds a Route for a specific HTTP Method.





SYNTAX

Add-PodeRoute -Method <String> -Path <String> [-Middleware <Object[]>] [-ScriptBlock <ScriptBlock>] [-Protocol

<String>] [-Endpoint <String>] [-EndpointName <String>] [-ContentType <String>] [-ErrorContentType <String>]

[-ArgumentList <Object[]>] [<CommonParameters>]



Add-PodeRoute -Method <String> -Path <String> [-Middleware <Object[]>] [-Protocol <String>] [-Endpoint <String>]

[-EndpointName <String>] [-ContentType <String>] [-ErrorContentType <String>] -FilePath <String> [-ArgumentList

<Object[]>] [<CommonParameters>]





DESCRIPTION

Adds a Route for a specific HTTP Method, with path, that when called with invoke any logic and/or Middleware.





PARAMETERS

-Method <String>

The HTTP Method of this Route.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Path <String>

The URI path for the Route.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Middleware <Object[]>

An array of ScriptBlocks for optional Middleware.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ScriptBlock <ScriptBlock>

A ScriptBlock for the Route's main logic.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Protocol <String>

The protocol this Route should be bound against.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Endpoint <String>

The endpoint this Route should be bound against.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-EndpointName <String>

The EndpointName of an Endpoint this Route should be bound against.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ContentType <String>

The content type the Route should use when parsing any payloads.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ErrorContentType <String>

The content type of any error pages that may get returned.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-FilePath <String>

A literal, or relative, path to a file containing a ScriptBlock for the Route's main logic.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ArgumentList <Object[]>

An array of arguments to supply to the Route's ScriptBlock.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Add-PodeRoute -Method Get -Path '/' -ScriptBlock { /* logic */ }













-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Add-PodeRoute -Method Post -Path '/users/:userId/message' -Middleware (Get-PodeCsrfMiddleware) -ScriptBlock

{ /* logic */ }













-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Add-PodeRoute -Method Post -Path '/user' -ContentType 'application/json' -ScriptBlock { /* logic */ }













-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Add-PodeRoute -Method Get -Path '/api/cpu' -ErrorContentType 'application/json' -ScriptBlock { /* logic */ }













-------------------------- EXAMPLE 5 --------------------------



PS C:\\>Add-PodeRoute -Method Get -Path '/' -ScriptBlock { /* logic */ } -ArgumentList 'arg1', 'arg2'















RELATED LINKS