-
Notifications
You must be signed in to change notification settings - Fork 1
Controllers
Ratnadeep Deb edited this page Dec 10, 2016
·
2 revisions
Each actions in controller takes PSR7 Request and Response as parameters. Bellow is an example of controller.
namespace ProfcartAPI\Controllers;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class IndexController
{
public function getIndex(RequestInterface $request, ResponseInterface $response) {
$response = $response->withData([
'ket' => 'value'
]);
return $response;
}
public function postIndex(RequestInterface $request, ResponseInterface $response) {
$response = $response->withData([
'message' => 'Data added'
]);
return $response;
}
public function putIndex(RequestInterface $request, ResponseInterface $response) {
$response = $response->withData([
'name' => 'Data updated'
]);
return $response;
}
}
Action names prefix with "get/post/put/delete" to indicate HTTP method.