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; }