承接 denismitr/net-call 相关项目开发

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

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

denismitr/net-call

Composer 安装命令:

composer require denismitr/net-call

包简介

Easy to use and mockable HTTP client, wraps most common http calls functionality around Guzzle.

README 文档

README

NetCall is a convenient and easy to use HTTP client. It is a wrapper around Guzzle, made for most common use cases. And is designed to make development and testing easier and more pleasant.

Author

Denis Mitrofanov

Installation

composer require denismitr/net-call

Usage

$response = NetCall::new()->get('http://www.google.com?foo=bar');

// NetCallResponseInterface methods
$response->body(); // : string
$response->json(); // : array
$response->header('some-key');
$response->headers(); // : array
$response->status(); // : int
$response->isSuccess(); // : bool
$response->isOk(); // : bool
$response->isRedirect(); // : bool
$response->isServerError(); // : bool
// request params will be json encoded by default
$response = NetCall::new()->post('http://test.com/post', [
    'foo' => 'bar',
    'baz' => 'qux',
]);

$response->json();
// array with json response data

From Params

$response = NetCall::new()->asFormData()->post('http://myurl.com/post', [
    'foo' => 'bar',
    'baz' => 'qux',
]);

Multipart

$response = NetCall::new()->asMultipart()->post('http://myurl.com/multi-part', [
    [
        'name' => 'foo',
        'contents' => 'bar'
    ],
    [
        'name' => 'baz',
        'contents' => 'qux',
    ],
    [
        'name' => 'test-file',
        'contents' => 'test contents',
        'filename' => 'test-file.txt',
    ],
]);

With Headers

$response = NetCall::new()
    ->withHeaders(['Custom' => 'Header'])
    ->get('http://myurl.com/get');

Set Accept header

$response = NetCall::new()
    ->accept('application/json')
    ->post('http://myurl.com/post');

Patch requests are supported

$response = NetCall::new()->patch('http://myurl.com/patch', [
    'foo' => 'bar',
    'baz' => 'qux',
]);

Exceptions

Exceptions are not thrown on 4xx and 5xx: use response status method instead.

Redirects

Redirects are followed by default

To disable that:

$response = NetCall::new()->noRedirects()->get('http://myurl.com/get');

$response->status(); // 302
$response->header('Location'); // http://myurl.com/redirected

Auth

Basic auth

$response = NetCall::new()
    ->withBasicAuth('username', 'password')
    ->get('http://myurl.com/basic-auth');

Digest auth

$response = NetCall::new()
    ->withDigestAuth('username', 'password')
    ->get('http://myurl.com/digest-auth');

Timeout

Set timeout

NetCall::new()->timeout(1)->get('http://myurl.com/timeout');

// If more then a second passes
// \Denismitr\NetCall\Exceptions\NetCallException is thrown

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固