承接 jenchik/http 相关项目开发

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

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

jenchik/http

最新稳定版本:1.3.0

Composer 安装命令:

composer require jenchik/http

包简介

Fork from vinelab/http with some adjustments for own use.

README 文档

README

###Forked from vinelab/http on github.org

http://Client

A smart and simple HTTP client for sending and recieving JSON and XML.

Installation

Composer

  • "jenchik/http": "dev-master" for the latest version installation instructions.
// change this to point correctly according
// to your folder structure.
require './vendor/autoload.php';

use Spc\Http\Client as HttpClient;

$client = new HttpClient;

$response = $client->get('echo.jsontest.com/key/value/something/here');

var_dump($response->json());

Laravel

Edit app.php and add 'Spc\Http\HttpServiceProvider', to the 'providers' array.

It will automatically alias itself as HttpClient so no need to alias it in your app.php, unless you would like to customize it - in that case edit your 'aliases' in app.php adding 'MyHttp' => 'Spc\Http\Facades\Client',

Usage

GET

Simple

	$response = HttpClient::get('http://example.org');

	// raw content
	$response->content();

With Params

	$request = [
		'url' => 'http://somehost.net/something',
		'params' => [

			'id'     => '12350ME1D',
			'lang'   => 'en-us',
			'format' => 'rss_200'
		]
	];

	$response = HttpClient::get($request);

	// raw content
	$response->content();

	// in case of json
	$response->json();

	// XML
	$response->xml();

POST

	$request = [
		'url' => 'http://somehost.net/somewhere',
		'params' => [

			'id'     => '12350ME1D',
			'lang'   => 'en-us',
			'format' => 'rss_200'
		]
	];

	$response = HttpClient::post($request);

	// raw content
	$response->content();

	// in case of json
	$response->json();

	// XML
	$response->xml();

Headers

$response = HttpClient::get([
	'url' => 'http://some.where.url',
	'headers' => ['Connection: close', 'Authorization: some-secret-here']
]);

// The full headers payload
$response->headers();

Enforce HTTP Version

HttpClient::get(['version' => 1.1, 'url' => 'http://some.url']);

Raw Content

HttpClient::post(['url' => 'http://to.send.to', 'content' => 'Whatever content here may go!']);

Custom Query String

The content passed in the content key will be concatenated to the URL followed by a ?

HttpClient::get(['url' => 'http://my.url', 'content' => 'a=b&c=d']);

It is pretty much the same process with different HTTP Verbs. Supports GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD

TODO

  • Improve tests to include testing all the methods of response (like statusCode...)
  • Include tests for handling bad data / errors
  • Improve tests to include testing for all HTTP Verbs

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-04