Web Page consists of a series of Resources
Example of simple HTTP request and response
GET / HTTP/1.1⏎
Host: mendelu.cz⏎
⏎
/
represents path from URL and mendelu.cz
is hostname
GET /welcome.php?name=John HTTP/1.1⏎
Host: domain.tld⏎
⏎
welcome.php:
POST /login.php?l=en HTTP/1.1⏎
Host: domain.tld⏎
Content-Type: application/x-www-form-urlencoded⏎
Content-Length: 48⏎
⏎
username=John&password=NotTooSecret&action=login
welcome.php:
welcome.latte
welcome.latte
layout.latte
Real layout is slightly bigger!
HTTP request:
GET /welcome?name=John HTTP/1.1⏎
Host: domain.tld⏎
⏎
Requeste handler:
$app->get('/welcome', function (Request $request, Response $response) {
$tplVars = ['username' => $request->getQueryParam('name')];
return $this->view->render($response, 'welcome.latte', $tplVars);
);
$app->get('/welcome', function (Request $request, Response $response) {
$data = $request->getParsedBody();
if (($data['username'] == 'JohnDoe') &&
($data['password'] == 'NotSoSecret')) {
$tplVars = [
'username' => $data['username'],
'language' => $request->getQueryParam('l'),
];
return $this->view->render($response, 'welcome.latte', $tplVars);
} else {
$tplVars = [
'language' = $request->getQueryParam('l')
];
return $this->view->render($response, 'login.latte', $tplVars);
}
);