api-router
api-router copied to clipboard
Custom matching routes
When I define custom matching routes and specify HTTP method for them, so that I'm able to access to specified route with any HTTP method.
Example of router definitions:
$apiRouter[] = new Routers\Route(
'api/message[/<action>]',
'Messages:Webhook:default',
[
'methods' => [
Nette\Http\Request::POST => 'click',
Nette\Http\Request::POST => 'deliver'
]
]);
And presenter:
class WebhookPresenter extends UI\Presenter
{
public function actionClick()
{
$this->sendJson([
'presenter' => 'Api:Message:Message',
'action' => 'click',
'timestamp' => time()
]);
}
public function actionDeliver()
{
$this->sendJson([
'presenter' => 'Api:Message:Message',
'action' => 'deliver',
'timestamp' => time()
]);
}
}
If I try to call URL via cURL with POST, I'll get correct response: {"presenter":"Api:Message:Message","action":"deliver","timestamp":1480584275}
But, if I call it with GET method, I'll get same response. FORBIDDEN or BAD_REQUEST is expected