All Projects → Vinelab → Http

Vinelab / Http

A smart, simple and fault-tolerant HTTP client for sending and receiving JSON and XML

Projects that are alternatives of or similar to Http

Easyhttp
A Laravel HTTP-client to make HTTP request easier and log requests and responses
Stars: ✭ 20 (-62.26%)
Mutual labels:  laravel, http-client
Laravel Messenger Bot Management
😄 Messenger bot Q&A management with Laravel
Stars: ✭ 52 (-1.89%)
Mutual labels:  laravel
Scout Elasticsearch Driver
This package offers advanced functionality for searching and filtering data in Elasticsearch.
Stars: ✭ 1,047 (+1875.47%)
Mutual labels:  laravel
Mangapie
This is a self-hosted server for archived manga.
Stars: ✭ 51 (-3.77%)
Mutual labels:  laravel
Intl Date Time
International DateTime for Laravel Nova
Stars: ✭ 50 (-5.66%)
Mutual labels:  laravel
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (-1.89%)
Mutual labels:  laravel
Cj Google Geocoder
Stars: ✭ 49 (-7.55%)
Mutual labels:  laravel
Authen
🚦 User Authentication Identifiers for Laravel
Stars: ✭ 53 (+0%)
Mutual labels:  laravel
Webshowu
webshowu—laravel开源项目—秀站分类目录源代码
Stars: ✭ 52 (-1.89%)
Mutual labels:  laravel
Qq
[READ ONLY] Subtree split of the SocialiteProviders/QQ Provider (see SocialiteProviders/Providers)
Stars: ✭ 50 (-5.66%)
Mutual labels:  laravel
Tech1 Benchmarks
Java JMH Benchmarks repository. No Longer Supported.
Stars: ✭ 50 (-5.66%)
Mutual labels:  http-client
Traefik Custom Error Pages
Bunch of custom error pages for Traefik 2.x built with Jekyll
Stars: ✭ 49 (-7.55%)
Mutual labels:  laravel
Laravel Oauth
Social OAuth authentication for Laravel 5 & 6. Drivers: Facebook, Twitter, Google, LinkedIn, Github, Bitbucket.
Stars: ✭ 52 (-1.89%)
Mutual labels:  laravel
Laravel Adminlte Components
Laravel Blade Components For AdminLTE Bootstrap Admin Template
Stars: ✭ 50 (-5.66%)
Mutual labels:  laravel
Hreq
A type dependent highlevel HTTP client library inspired by servant-client.
Stars: ✭ 53 (+0%)
Mutual labels:  http-client
Fluent Facebook
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
Stars: ✭ 49 (-7.55%)
Mutual labels:  laravel
Tailwindcss
A Tailwind CSS frontend preset for the Laravel Framework
Stars: ✭ 1,056 (+1892.45%)
Mutual labels:  laravel
Cross Fetch
Universal WHATWG Fetch API for Node, Browsers and React Native.
Stars: ✭ 1,063 (+1905.66%)
Mutual labels:  http-client
Laravel Collection Macros
A set of useful Laravel collection macros
Stars: ✭ 1,069 (+1916.98%)
Mutual labels:  laravel
Json Api Dart
JSON:API client for Dart/Flutter
Stars: ✭ 53 (+0%)
Mutual labels:  http-client

build status

Dependency Status

SensioLabsInsight

http://Client

A smart, simple and fault-tolerant HTTP client for sending and recieving JSON and XML.

Installation

Composer

composer require vinelab/http

// change this to point correctly according
// to your folder structure.
require './vendor/autoload.php';

use Vinelab\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 'Vinelab\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' => 'Vinelab\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();

Options

These options work with all requests.

Timeout

You can set the timeout option in order to specify the number of seconds that your request will fail, if not completed.

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

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

Headers

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

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

Basic Auth

$response = HttpClient::get([
	'url' => 'http://somehost.net/somewhere',
	'auth' => [
		'username' => 'user',
		'password' => 'pass'
	],
	'params' => [
		'var1'     => 'value1',
		'var2'   => 'value2'
	]
]);

Digest Auth

$response = HttpClient::get([
	'url' => 'http://some.where.url',
	'digest' => [
		'username' => 'user',
		'password' => 'pass'
	],
	'params' => [
		'var1'     => 'value1',
		'var2'   => 'value2'
	]
]);

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

Fault Tolerance

Fault tolerance allows the request to be re-issued when it fails (i.e. timeout). This is useful in cases such as Microservices: When a service is down and is being called by another service, with fault tolerance the request will be re-issued in the hopes of the destination service being up again.

Issue a fault-tolerant request by setting the tolerant flag to true in the request. Also, specify the time it should wait until it tries again with timeUntilNextTry (in seconds) and the number of tries before it is considered a failure with triesUntilFailure (in seconds).

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

		'id'     => '12350ME1D',
		'lang'   => 'en-us',
		'format' => 'rss_200'
	],
	'timeout' => 10
	'tolerant' => true,
	'timeUntilNextTry' => 1,
	'triesUntilFailure' => 3
];

In case of timeout occurance, a HttpClientRequestFailedException will be thrown.

IMPORTANT! Notice: In order to make use of fault tolerance option, you must specify the timeout parameter too.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].