Download the PHP package innmind/http-transport without Composer
On this page you can find all versions of the php package innmind/http-transport. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download innmind/http-transport
More information about innmind/http-transport
Files in innmind/http-transport
Package http-transport
Short Description Library to fulfill http resquest
License MIT
Homepage http://github.com/Innmind/HttpTransport
Informations about the package http-transport
HttpTransport
This library allows you to send http request.
Important: to use this library correctly you must use vimeo/psalm
.
Installation
Usage
Send a request:
2xx
responses will be on the right side of $either
, all errors and other kinds of responses will be on the left side.
Important: you must call match
to the returned Either
otherwise the request will not be sent, but you can still call other methods on the Either
before calling match
.
Concurrency
By default there is no limit of concurrency for the Curl
transport. But if you call many requests before unwrapping the results you may want to configure the max concurrency like below.
Let's say you have 100
urls to fetch, there will never be more than 5
requests being done in parallel.
Log the request
You can easily log all your requests like so:
Here a message is logged before the request is sent and another one once it's sent.
Exponential Backoff
Sometimes when calling an external API it may not be available due to heavy load, in such case you could retry the http call after a certain amount of time leaving time for the API to recover. You can apply this pattern like so:
By default it will retry 5 times the request if the server is unavailable, following the given periods (in milliseconds) between each call: 100
, 271
, 738
, 2008
and 5459
.
Circuit breaker
When a call to a certain domain fails you may want to all further calls to that domain to fail immediately as you know it means the host is down. Such pattern is called a circuit breaker.
This code will open the circuit for a given domain for 10 minutes in case a call results in a server error, after this delay the transport will let new request through as if nothing happened.
Follow redirections
By default the transports do not follow redirections to give you full control on what to do. But you can wrap your transport with FollowRedirections
like this:
To avoid infinite loops it will follow up to 5 consecutive redirections.
Important: as defined in the rfc, requests with methods other than GET
and HEAD
that results in redirection with the codes 301
, 302
, 307
and 308
will NOT be redirected. It will be up to you to implement the redirection as you need to make sure such redirection is safe.
All versions of http-transport with dependencies
ext-curl Version *
innmind/http Version ~7.0
innmind/filesystem Version ~7.1
innmind/stream Version ~4.0
psr/log Version ~3.0
ramsey/uuid Version ^4.7
innmind/time-warp Version ~3.0
innmind/time-continuum Version ~3.0
innmind/immutable Version ~4.15|~5.0
innmind/url Version ~4.0
innmind/io Version ~2.2