Skip to content

Configuration

Wes Rice edited this page Feb 11, 2016 · 10 revisions

First, ensure that craft/config/httpmessages.php exists. All routes that need to utilize Http Messages will be defined in this file.

Example Configuration

<?php

return [

    'routes' => [

        '<pattern>' => [
            '<http method>' => [
                '<middleware handle>' => [<middleware config>]
            ],
        ],

    ],

];
Patterns

Patterns can either be static or dynamic. Static patterns will require the pattern matches the uri path verbatim. Dynamic patterns allow you to define path variables that are accessible throughout the middleware stack.

Path variables are defined by wrapping a name and an option regex pattern inside of curly braces, separated by a colon.

'/api/blog' 
// Only Match: /api/blog

'/api/planet/{planet}'
// Matches: /api/planet/earth, /api/planet/mars, /api/planet/2
// Doesn't Match: /api/planet/pluto/moons

'/api/blog/{id:[0-9]+}'
// Matches: /api/blog/1, /api/blog/2
// Doesn't Match: /api/blog/my-post, /api/blog/1/comments

Portions of the path can me made optional by wrapping the optional part of the path in square brackets.

'/api/blog[/{slug}]' 
// Matches: /api/blog /api/blog/my-post
// Doesn't Match: 
Http Methods

(todo)

Middleware Handles

(todo)

Clone this wiki locally