swnck/pure-request
Composer 安装命令:
composer require swnck/pure-request
包简介
A streamlined PHP library for hassle-free HTTP requests, simplifying web communication without the complexity of cURL.
README 文档
README
⚠️ UNDER DEVELOPMENT ⚠️
Introduction
PureRequest is a streamlined PHP library designed to simplify web communication by providing a hassle-free interface for HTTP requests, eliminating the complexity of using cURL directly. This library supports a wide range of HTTP operations, including GET and POST requests, and is highly configurable to meet the needs of various web applications.
Features
- Easy-to-use interface for HTTP GET and POST requests
- Support for custom headers and body content
- Configurable request options, including timeouts and redirection handling
- Built-in support for handling response data and status codes
- Secure and efficient implementation
Installation
To install PureRequest, you need to have Composer installed on your machine. Run the following command in your project directory:
composer require swnck/pure-request
Usage
Configuration of Request
$request = new PureRequest((new RequestConfiguration()) ->setReturnTransfer(true) // Return the transfer as a string of the return value of curl_exec() instead of outputting it out directly ->setFollowLocation(true) // Follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set) ->setConnectTimeout(10) // The maximum number of seconds to allow cURL functions to execute );
or if you want to stay with DEFAULT configuration:
$request = new PureRequest();
Sending a GET Request
$request->get(HeaderContent::empty(), function (ResponseFrame $response) { echo $response->getContent(); echo $response->getStatusCode(); }, "https://example.com/api/data");
Sending a POST Request
$request->post(HeaderContent::paste(["Content-Type" => ContentType::APPLICATION_JSON, "Connection" => "keep-alive"]), BodyContent::paste([ "email" => "user@example.com", "password" => "your_password" ]), function (ResponseFrame $response) { echo $response->getContent(); }, "https://example.com/api/login");
Features
- Easy-to-use interface for HTTP GET and POST requests
- Support for custom headers and body content
- Support for PUT, DELETE, PATCH, OPTIONS, HEAD, and other HTTP methods
- Support for file uploads and multipart form data
- Configurable request options, including timeouts and redirection handling
- Built-in support for handling response data and status codes
- Secure and efficient implementation
- Support for cookies and session management
- Support for asynchronous requests and parallel processing
Contributing
We welcome contributions from the community! If you'd like to contribute to PureRequest, please fork the repository and submit a pull request with your proposed changes or improvements.
License
The contents of this repository are licensed under the Apache License, version 2.0.
swnck/pure-request 适用场景与选型建议
swnck/pure-request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 swnck/pure-request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swnck/pure-request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-03-19