blob: b7a0311fb6731932fe9441367f2d5adb04543bbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
{
if ($req->getHeaderLine("Content-Type") != 'application/json') {
$resp->getBody()->write("invalid content-type");
return $resp;
}
// we expect json body
$p = json_decode($req->getBody(), true);
$resp->getBody()->write(json_encode(array_flip($p)));
return $resp;
}
|