rdj/client
Composer 安装命令:
composer require rdj/client
包简介
This Package for Laravel Client Consume API (Web Service)
README 文档
README
This Package for Laravel Client Consume API (Web Service)
Requirement
In Your Project you must install guzzlehttp/guzzle version 6.2 or latest version.
Install Package Composer
There are 2 ways to install this package :
Install via "composer"
$ composer require rdj/client "dev-master"
or
Add the manual in composer.json
Step 1
{
...
"require"{
"rdj/client" : "dev-master"
}
}
Step 2
$ composer update
Integration on Laravel Config
Register the Provider in the config/app.php file:
'providers' => [
....
Rdj\Client\ClientServiceProvider::class,
]
Add facade aliases in the same file config / app.php:
'aliases' => [
....
'Client' => Rdj\Client\Facades\Client::class,
]
Publish the package configuration file using the following command:
$ php artisan vendor:publish
Setting Enviroment (.env)
Edit file .env add the following code:
WEB_SERVER_URI=your_web_server_uri (e.g: https://webserver.com/ )
BASE=your_base (e.g: int/ or eks/ or mobile/ or api/v1/ )
How to use
In your controller:
Get data from your web server without authorization in header:
....
use Client;
Class YourController extends Controller
{
....
public function getData()
{
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders([])
->setQuery([])
->get();
return response()->json( $getdata );
}
}
Get data from your web server with authorization in header:
....
use Client;
Class YourController extends Controller
{
....
public function getData()
{
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setQuery([])
->get();
return response()->json( $getdata );
}
}
Get data from your web server with authorization in header and parameter query:
....
use Client;
Class YourController extends Controller
{
....
public function getData(Request $request)
{
$search = $request->search;
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setQuery(['search' => $search])
->get();
return response()->json( $getdata );
}
}
Post data from your web server with authorization in header and parameter body:
....
use Client;
Class YourController extends Controller
{
....
public function postData(Request $request)
{
$param_post = $request->all();
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setBody($param_post)
->post();
return response()->json( $getdata );
}
}
Multipart Post data from your web server with authorization in header and parameter body:
....
use Client;
Class YourController extends Controller
{
....
public function postDataMultipart(Request $request)
{
$param_post = $request->all();
$getdata = Client::setEndpoint('your_endpoint')
->setHeaders(['authorization' => 'your_token'])
->setBody($param_post)
->post('multipart');
return response()->json( $getdata );
}
}
Delete data from your web server with authorization in header and parameter body:
....
use Client;
Class YourController extends Controller
{
....
public function DeleteData($id)
{
$getdata = Client::setEndpoint('your_endpoint/'.$id)
->setHeaders(['authorization' => 'your_token'])
->deleted();
return response()->json( $getdata );
}
}
Contributing
- Fork it (https://github.com/ranggadarmajati/LaravelClient/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request
License
This Package have license under MIT License
rdj/client 适用场景与选型建议
rdj/client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.36k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rdj/client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rdj/client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-05-13
