summaryrefslogtreecommitdiff
path: root/tests/http/payload.php
blob: 52c0f819b38612bb74bc16ce09e94190affc61db (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;
}