melquespaiva / rest-response
一个用于管理Restful API响应的项目
v1.0.1
2021-06-08 14:32 UTC
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
README
管理Restful API响应的项目
Rest Response 是一个简单且优化的小型库,用于管理您的 API 的 HTTP 响应
Rest Response 是一个简单且优化的小型库,用于管理您的 API 的 HTTP 响应
亮点
- 简单安装(安装简单)
- 针对主要 HTTP 响应代码的优化响应(针对主要 HTTP 响应代码的优化响应)
- 为库中未实现的自定义 HTTP 响应代码提供简单的方法(为库中未实现的自定义 HTTP 响应代码提供简单的方法)
- Composer 准备就绪且符合 PSR-2 规范(准备就绪且符合 PSR-2 规范的 Composer)
安装
通过 Composer 可用
"melquespaiva/rest-response": "^1.0"
或运行
composer require melquespaiva/rest-response
文档
有关如何使用的详细信息,请参阅组件目录中的示例文件夹。
有关如何使用的详细信息,请参阅组件目录中的示例文件夹。
<?php require __DIR__ . "/../vendor/autoload.php"; $response = new Response(); // call response statusCode 200 $data = [ "user" => [ "name" => "Melques", "last_name" => "Paiva", "document" => "123456456" ] ]; $response->successful("The request was finish with success", $data); // call response statusCode 204 $response->noContent(); // call response other to other statusCode, but still a successfull response $success = new Success(); $success->setStatusCode(203) ->setData(["user" => "Melques Paiva"]) ->setMessage("A generic message") ->setType("generic_type"); echo $response->successfullResponse($success); // call response with statusCode 400 $response->badRequest("The data passed to this request is not valid", "parameter_if_necessary"); // call response with statusCode 401 $response->unauthorized( "You don't have authorization or you aren't authenticate to access this method", "parameter_if_necessary" ); // call response with statusCode 403 $response->actionForbidden( "The server understood the request, but you can't receive a succesfull response" ); // call response with statusCode 404 $response->notFound("No information founded", "parameter_if_necessary"); // call response with statusCode 405 $response->methodNotAllowed( "The method with you trying to access this method is not allowed", "parameter_if_necessary" ); // call response with statusCode 500 $response->internalError("Some errors occurred on the server side"); // call response with statusCode 501 $response->methodNotImplemented("This method still isn't impelemented"); // call response on a other statusCode error $error = new Error(); $error->setStatusCode(402) ->setMessage("Payment Required") ->setType("payment_required"); echo $response->errorResponse($error) ?>
贡献
有关详细信息,请参阅CONTRIBUTING。
支持
安全:如果您发现任何与安全相关的问题,请通过melque1703@gmail.com 发送电子邮件,而不是使用问题跟踪器。
如果您发现任何与安全相关的问题,请通过melque1703@gmail.com 发送电子邮件,而不是使用问题跟踪器。
谢谢
致谢
- Melques S. Paiva(开发者)
- 所有贡献者(这是基石)
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。