api-router icon indicating copy to clipboard operation
api-router copied to clipboard

Custom matching routes

Open hurvajs77 opened this issue 8 years ago • 0 comments

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

hurvajs77 avatar Dec 01 '16 10:12 hurvajs77