sms516
3/20/2019 - 10:26 PM

Specify which HTTP method a URL handler

Did you know that you can specify which HTTP method a URL handler should accept? For example, to only allow GET requests to an endpoint that doesn't handle submissions:

```$url_handlers = [
    'GET my-endpoint' => 'getMyEndpoint',
];```

This also allows you to call different Controller methods for different HTTP methods sent to the same endpoint, making your code tidier:

```$url_handlers = [
    'GET my-endpoint' => 'getMyEndpoint',
    'POST my-endpoint' => 'submitMyEndpoint',
];```

The only caveat to watch out for: If you want to match on the root (e.g. the equivalent of '' => 'getIndex'), you currently have to chuck an extra space on the end: 'GET ' => 'getIndex')