khalyomede/pulsar-php
Composer 安装命令:
composer require khalyomede/pulsar-php
包简介
API request and response, without using CURL.
README 文档
README
API request and response, without using CURL.
Summary
Installation
In your project, add the following dependency:
composer require khalyomede/pulsar-php:3.*
PHP support
To use this library for PHP 5.3+ until 5.6, use the version 1.* of this library. Note the version 1 and 2 are no longer maintainted.
Examples
- Sending a GET request
- Sending a POST request
- Sending a PATCH request
- Sending a PUT request
- Sending a DELETE request
- Sending a request to a non existing endpoint
- Get the response as an array
- Get the HTTP status code
Sending a GET request
require(__DIR__ . '/../vendor/autoload.php'); $content = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1')->content(); print_r($content);
stdClass Object ( [userId] => 1 [id] => 1 [title] => sunt aut facere repellat provident occaecati excepturi optio reprehenderit [body] => quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto )
Sending a POST request
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->data([ 'title' => 'Test your PHP libraries with Matcha', 'userId' => 1, 'body' => 'Lorem ipsum' ])->post('https://jsonplaceholder.typicode.com/posts'); print_r($response->content());
stdClass Object ( [title] => Test your PHP libraries with Matcha [userId] => 1 [body] => Lorem ipsum [id] => 101 )
Sending a PATCH request
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->data([ 'name' => 'morpheus', 'job' => 'zion resident' ])->patch('https://reqres.in/api/users/2'); print_r($response->content());
stdClass Object ( [name] => morpheus [job] => zion resident [updatedAt] => 2018-06-18T21:29:15.334Z )
Sending a PUT request
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->data([ 'name' => 'neo', 'job' => 'developer at Metacortex' ])->put('https://reqres.in/api/users/2'); print_r($response->content());
stdClass Object ( [name] => neo [job] => developer at Metacortex [updatedAt] => 2018-06-20T09:46:44.267Z )
Sending a DELETE request
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->delete('https://reqres.in/api/users/2'); echo $response->code();
204
Sending a request to a non existing endpoint
In this case, you will always get a 404 status code and an empty response.
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->get('https://a-non-existing-domain-hopefully.com/api/v1/post'); echo $response->code();
404
Get the response as an array
You can do so by using ->toArray() modifier:
require(__DIR__ . '/../vendor/autoload.php');
Get the response as an array
You can use the toArray() modifier for this purpose:
require(__DIR__ . '/../vendor/autoload.php'); $array = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1')->toArray()->content(); print_r($array);
Which is the same as:
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1'); $array = $response->toArray()->content(); print_r($array);
Array ( [userId] => 1 [id] => 1 [title] => sunt aut facere repellat provident occaecati excepturi optio reprehenderit [body] => quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit molestiae ut ut quas totam nostrum rerum est autem sunt rem eveniet architecto )
Get the HTTP status code
require(__DIR__ . '/../vendor/autoload.php'); $response = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1'); echo $response->code();
200
Credits
- Logo by Anthony Ledoux from Noun Project (the current version is modified, this is the original version)
khalyomede/pulsar-php 适用场景与选型建议
khalyomede/pulsar-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 2, 最近一次更新时间为 2017 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 khalyomede/pulsar-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 khalyomede/pulsar-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-30