getBody()->write(json_encode($result)); return $response->withHeader("Content-Type", "application/json"); } public static function post( ServerRequestInterface $request, ResponseInterface $response, array $args ): ResponseInterface { $contentType = $request->getHeaderLine("Content-Type"); switch ($contentType) { case "application/json": $body = json_decode(file_get_contents("php://input"), true); break; default: break; } //there's only one verion of the api for now switch (isset($args["third"]) ? $args["third"] : "none") { case "login": $result = Auth::login($body); break; case "logout": $result = Auth::logout($body); break; default: $result = [ "message" => "Oh, nothing to do. That's unfortunate", "type" => "TASK_NONE", ]; break; } $response->getBody()->write(json_encode($result)); return $response->withHeader("Content-Type", "application/json"); } }