HTTP 请求和响应的网关和方式

dev-main 2021-10-18 00:28 UTC

This package is auto-updated.

Last update: 2024-09-18 03:57:19 UTC


README

HTTP 请求和响应的网关和方式

目录

下载

composer require requests.php/php
git clone https://github.com/BrunoBeltreGuzman/requests.php.git

Download.zip

注意

您可以删除 test 目录和 README.mdindex.php 文件。

用法

请求

注意

在请求 PUT、PATCH 和 DELETE 发送数据时,您可以使用 x-www-form-urlencoded 表单

响应

函数

参数

测试

请求

请求: GET 请求

Request::get(function (Response $response) {
       //you do anything
});

请求: POST 请求

Request::post(function (Response $response) {
       //you do anything
});

请求: PUT 请求

Request::put(function (Response $response) {
       //you do anything
});

请求: PATCH 请求

Request::patch(function (Response $response) {
       //you do anything
});

请求: DELETE 请求

Request::delete(function (Response $response) {
       //you do anything
});

用法

use Requests\Php\Request;
use Requests\Php\Response;

include __DIR__ . "/../vendor/autoload.php";

// {id}
Request::get(function (Response $response) { {
       try {
              $GET = $response->getParameters();
              if ($GET["id"]) {
                     $data = [array('id' => $GET["id"])];
                     $response->response($data);
              } else {
                     $response->response("BadRequest", 400);
              }
       } catch (Exception $exception) {
              $response->response($exception, 500);
       }
});

MIT 许可证

版权 (c) 2021 @BrunoDev

以下对本软件及其相关文档(以下简称“软件”)的副本的任何个人,在此免费授予在不限制的前提下使用该软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件副本,并允许向提供软件的个人提供此类行为,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定目的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他方式,无论这些责任是否源于、源于或与软件或其使用或其他交易有关。

参考

https://www.restapitutorial.com/httpstatuscodes.html