Skip to content

Add-PodeRoute

SYNOPSIS

Adds a Route for a specific HTTP Method.

SYNTAX

Script (Default)

Add-PodeRoute -Method <String> -Path <String> [-Middleware <Object[]>] [-ScriptBlock <ScriptBlock>]
 [-EndpointName <String[]>] [-ContentType <String>] [-TransferEncoding <String>] [-ErrorContentType <String>]
 [-ArgumentList <Object[]>] [-Authentication <String>] [-Login] [-Logout] [-PassThru] [<CommonParameters>]

File

Add-PodeRoute -Method <String> -Path <String> [-Middleware <Object[]>] [-EndpointName <String[]>]
 [-ContentType <String>] [-TransferEncoding <String>] [-ErrorContentType <String>] -FilePath <String>
 [-ArgumentList <Object[]>] [-Authentication <String>] [-Login] [-Logout] [-PassThru] [<CommonParameters>]

DESCRIPTION

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

EXAMPLES

EXAMPLE 1

Add-PodeRoute -Method Get -Path '/' -ScriptBlock { /* logic */ }

EXAMPLE 2

Add-PodeRoute -Method Post -Path '/users/:userId/message' -Middleware (Get-PodeCsrfMiddleware) -ScriptBlock { /* logic */ }

EXAMPLE 3

Add-PodeRoute -Method Post -Path '/user' -ContentType 'application/json' -ScriptBlock { /* logic */ }

EXAMPLE 4

Add-PodeRoute -Method Post -Path '/user' -ContentType 'application/json' -TransferEncoding gzip -ScriptBlock { /* logic */ }

EXAMPLE 5

Add-PodeRoute -Method Get -Path '/api/cpu' -ErrorContentType 'application/json' -ScriptBlock { /* logic */ }

EXAMPLE 6

Add-PodeRoute -Method Get -Path '/' -ScriptBlock { /* logic */ } -ArgumentList 'arg1', 'arg2'

PARAMETERS

-ArgumentList

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

Type: Object[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Authentication

The name of an Authentication method which should be used as middleware on this Route.

Type: String
Parameter Sets: (All)
Aliases: Auth

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ContentType

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

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-EndpointName

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

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ErrorContentType

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

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-FilePath

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

Type: String
Parameter Sets: File
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Login

If supplied, the Route will be flagged to Authentication as being a Route that handles user logins.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Logout

If supplied, the Route will be flagged to Authentication as being a Route that handles users logging out.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Method

The HTTP Method of this Route.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Middleware

An array of ScriptBlocks for optional Middleware.

Type: Object[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

If supplied, the route created will be returned so it can be passed through a pipe.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Path

The URI path for the Route.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ScriptBlock

A ScriptBlock for the Route's main logic.

Type: ScriptBlock
Parameter Sets: Script
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-TransferEncoding

The transfer encoding the Route should use when parsing any payloads.

Type: String
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.

INPUTS

OUTPUTS

NOTES