承接 swnck/pure-request 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

swnck/pure-request

最新稳定版本:1.0.1

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.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-03-19