Download the PHP package chroma-x/basic-http-client without Composer

On this page you can find all versions of the php package chroma-x/basic-http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package basic-http-client

PHP Basic HTTP Client

Build Status SensioLabs Insight Code Climate Codacy Badge Latest Stable Version Total Downloads License

A basic yet extensible HTTP client library providing different authentication methods written in PHP.

What about PSR-7?

PHP Basic HTTP Client is an alternative to other very good implementations like Guzzle that are following the PSR-7 guidelines.

This project not follows these guidelines for different reasons.

  1. PSR-7 is heavily over engineered due to also match complex edge cases.
  2. Objects implementing the PSR-7 interfaces have to be immutable wich is resulting in an unusual API from the PHP dev point of view and an unneccessarily increased need of performance.

Find out more at the „PSR-7 is imminent, and here's my issues with it“ blog post by PHP-FIG member Evert Pot and this discussion at Stackoverflow.

Installation

Usage

Autoloading and namesapce

Simple usage

Preparing the HTTP client

Performing requests and read the response

Body-less requests (GET, HEAD and DELETE)

Perfoming the following GET request with additional query parameters

will result in the following HTTP request.

The same mechanic is offered to perform HEAD and DELETE requests wich all are body-less.

Body-full requests (POST, PUT, PATCH)

Perfoming the following POST request with body data

will result in the following HTTP request.

The same mechanic is offered to perform PUT and PATCH requests wich all are body-full.


Detailed usage

The following example shows the usage with a more detailed configuration.

Configuring an HTTP Transport instance

Configuring an HTTPS Transport instance

Configuring a Message instance with Body

Message and request Header instances

Please note, that headers have some unusual behaviours. Header names have an uniform way of nomenclature so the following three getter calls would have the same result.

To allow multiple request headers using the same name, the method addAdditionalHeader provides such a logic.

Configuring an endpoints URL, build the Request instance and perform the HTTP request

For more information about the usage of the URL object please take a look at the PHP URL Util project.

The resulting HTTP request would be the following.

Usage of authentication methods

You can add one or more Authentication instances to every Request instance. At the moment this project provides classes for HTTP Basic Authentication and SSL Client Certificate Authentication.

HTTP Basic Authentication

Required credentials are a username and a password that get provided to the class constructor as arguments.

SSL Client Certificate Authentication

Required credentials are a Certificate Authority Certificate, a Client Certificate and the password that is used to decrypt the Client Certificate that get provided to the class constructor as arguments.


Reading from the resulting Response object

Getting the response object

If using the BasicHttpClient the response object is returned by the termination methods listed above. If directly using the Request instance, you can get the Response object via a getter.


Getting effective Request information

After successful performing the request, the effective request information is tracked back to the Request object. They can get accessed as follows.


Getting some transactional statistics


Extending the Basic HTTP Client

Every part of the client is based upon proper interfaces. Most class instances can get injected into the client itself. If you want to extend the client just write some classes implementing the according interface and you´re done with that.

Take a look at the PHP JSON HTTP Client which is an extension of the PHP Basic HTTP Client.


Exception handling

PHP Basic HTTP Client provides different exceptions – also provided by the PHP Common Exceptions project – for proper handling.
You can find more information about PHP Common Exceptions at Github.

Exceptions to be expected

In general you should expect that any setter method could thrown an \InvalidArgumentException. The following exceptions could get thrown while using PHP Basic HTTP Client.


Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.

License

PHP Basic HTTP Client is under the MIT license.


All versions of basic-http-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-curl Version *
ext-mbstring Version *
chroma-x/url-util Version ~2.0
chroma-x/common-exceptions Version ~3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package chroma-x/basic-http-client contains the following files

Loading the files please wait ....