Download the PHP package simplecomplex/http without Composer
On this page you can find all versions of the php package simplecomplex/http. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download simplecomplex/http
More information about simplecomplex/http
Files in simplecomplex/http
Package http
Short Description High-level HTTP client and (Slim) service utility. Client provides response validation and mocking; service provides standardized and predictable responses.
License MIT
Homepage https://github.com/simplecomplex/php-http
Informations about the package http
Http
High-level HTTP client and (Slim) service utility.
Client provides response validation and mocking.
Service provides standardized and predictable responses.
### ▹ Client ###
#### Request options #### The method accepts it's own options as well as options for the underlying [RestMini Client](https://github.com/simplecomplex/restmini#client-options). ##### Own options ##### - (bool) **debug_dump**: log request and response - (bool|arr) **cacheable**: cache response/load response from [cache](https://github.com/simplecomplex/php-cache) - (bool|arr) **validate_response**: validate the response body against a [validation rule set](https://github.com/simplecomplex/php-validate) - (bool|arr) **mock_response**: don't send the request, return predefined mock response - (int) **retry_on_unavailable**: millisecs; try again later upon 503 Service Unavailable|host not found|connection failed - (arr) **require_response_headers**: list of response header keys required - (bool) **err_on_endpoint_not_found**: err on 404 + HTML response - (bool) **err_on_resource_not_found**: err on 204 or 404 + JSON response - (arr) **log_warning_on_status**: key is status code, value is true ##### Options processing ##### Apart from options passed directly to there may also exist settings (see [Config](https://github.com/simplecomplex/php-config)) for the: - **provider**: the service host - **service**: a group of endpoints - **endpoint**: the actual endpoint - **method**: literal HTTP method or an alias (like GET aliases index and retrieve) During request preparations settings and options get merged, so that – _options_ override _method_ settings, which override _endpoint_ settings, which override... (you get it). Sounds like a lot of work, but it isn't really.#### ▹▹ Client CLI commands ####
##### (remote) Service configuration ##### ##### Validation rule sets ##### ##### Mock responses ######### ▹▹ Client error codes ####
For every error code there's an equivalent prefab safe and user-friendly (localizable) error message. - : overall error fallback - : local error fallback - : in-package logical error - : invalid argument et al. - : bad config var - : bad option var - : RestMini Client or cURL cannot request - : DNS or actually no such host - : status 503 Service Unavailable - : too many redirects - : cURL 504 - : status 504 Gateway Timeout - : cURL 500 (RestMini Client 'response-false') - : status 500 Internal Server Error - : remote says 502 Bad Gateway - : unsupported 5xx status - : status 404 + Content-Type not JSON (probably HTML); no such endpoint - : status 204, status 404 + Content-Type JSON; no such resource (object) - : 400 Bad Request - : 412 Precondition Failed, 422 Unprocessable Entity - : content type mismatch - : parse error - : unsupported non-5xx status - : setting/option _require_response_headers_ - : response body validation failure; service will send X-Http-Response-Invalid header### ▹ Service ###
Producing a service response is not as hard as requesting a remote service, so the service part of **Http** is not as rich as the client part. It is assumed that one will simply echo something and send some headers – or use a service framework like [Slim](https://www.slimframework.com/). The class suggest means of interacting with Slim, and **Http** includes a simple example. @todo And **Http** also provides a few other service utilities. #### Allowing Cross Origin requests #### Preferably only at development site. Necessary when developing Angular-based frontend. Place a text file in document root, containing list allowed sites, like:#### ▹▹ Service error codes ####
For every error code there's an equivalent prefab safe and user-friendly (localizable) error message. - : overall fallback - : (some kind of) bad request; - : authentication (login) failure; - : authorization (permission) failure; - : request header/argument validation failure; - : frontend only; parse error - : frontend only; response validation failureService and client combined
Standardized wrapped response body
A service requestor should never be in doubt whether a request to your service went alltogether well.
returns object:
- status : suggested status to send to requestor
- headers : suggested headers to send
- body
- success
- status : status received from remote service
- data : that actual data (on success)
- message : safe and user-friendly message (on failure)
- code : error code (on failure), or optionally some other flag (on success)
- originalHeaders : headers received – not to be sent to requestor
- validated : whether the response was validated, and then the outcome
The general idea is to always send a response body containing metadata about the procedings – success, status, code.
And – on failure – a prefab safe and user-friendly message, which the client can use to inform the visitor
(instead of just failing silently/ungracefully).
When exposing a service that does a remote request, the service should however have access to more detailed info
about the remote request/response
– therefore the further wrapping in an object that suggests status and headers (et al.).
#### ▹ Service response headers ####
**Http** uses a number of custom response headers, to flag stuff to the client. Some are issued by upon every remote request (the original/final statuses). Others are only issued if a service uses/sends one of the prefab extensions. - (int): status received from remote service (or interpretated ditto) - (int): final status to be sent to client - : response validation failure; - : never called remote service; used prefab mock response - : request header/argument validation failure; - : (some kind of) bad request; - : authentication (login) failure; - : authorization (permission) failure;Requirements
- PHP >=7.0
- PSR-3 Log
- SimpleComplex Utils
- SimpleComplex Cache
- SimpleComplex Config
- SimpleComplex Locale
- SimpleComplex Validate
- SimpleComplex RestMini
- SimpleComplex Inspect
Suggestions
All versions of http with dependencies
ext-ctype Version *
psr/log Version ^1.0
simplecomplex/utils Version ^1.9 || ^2.0 || dev-develop
simplecomplex/cache Version ^1.3 || dev-develop
simplecomplex/config Version ^2.1 || dev-develop
simplecomplex/locale Version ^2.1 || dev-develop
simplecomplex/validate Version ^2.1 || ^1.0 || dev-develop
simplecomplex/restmini Version ^1.1.2 || dev-develop
simplecomplex/inspect Version ^3 || ^2.2.5 || dev-develop