Download the PHP package phpro/http-tools without Composer

On this page you can find all versions of the php package phpro/http-tools. 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 http-tools

Github Actions Installs Packagist

HTTP-Tools

The goal of this package is to provide you some tools to set-up a data-centric, consistent HTTP integration. The HTTP client implementation you want to use is just a small implementation detail and doesn't matter. However, here are some default guidelines:

Prerequisites

Choosing what HTTP package you want to us is all up to you. We do require a PSR implementations in order to install this package:

Installation

Setting up an HTTP client :

You can choose whatever HTTP client you want. However, this package provides some convenient factories that make the configuration a bit easier.

The factory accepts a list of implementation specific plugins / middlewares. Besides that, you can configure implementation-specific options like a base_uri or default headers.

You can always create your own factory if you want to have more control or want to use another tool!

Note: This package does not download a specific HTTP implementation. You can choose whatever package you want, but you'll have to manually add it to composer.

Configuring the client through plugins

Plugin-Middleware : Patato-Patato.

If you want to extend how an HTTP client works, we want you to use plugins! You can use plugins for everything: logging, authentication, language specification, ...

Examples:

Built-in plugins:

Remember: There are a shitload of HTTPlug middleware available already. Try on of them before writing your own one!

Logging

This package contains the php-http/logger-plugin. On top of that, we've added some decorators that help you strip out sensitive information from the logs. You can switch from full to simple logging by specifying a debug parameter!

More info ...

Using the HTTP-Client

We don't want you to use the PSR-18 client directly! Instead, we suggest you to use a request handler principle. So what does this architecture look like?

More information on Transports and Encodings

By using this architecture, we provide an easy to extend flow with models that replace cumbersome array structures.

You might be familiar with 1 "client" class that provides access to multiple API endpoints. We see that approach as a multi-requesthandler class. You are free to choose that approach, owever, we suggest using 1 request handler per API endpoint. This way, you can inject / mock only the things you require at that moment into your codebase.

Example implementation:

Example request handler:

This example is rather easy and might seem like overkill at first. The true power will be visible once you create multiple named constructors and conditional porperty accessors inside the request models. The response models, if crafted carefully, will improve the stability of your integration!

Async request handlers

In order to send async requests, you can use this package in combination with fiber-based PSR-18 clients. The architecture can remain as is.

An example client based on ReactPHP might be based on this:

(There currently is no official fiber based PSR-18 implementation of either AMP or ReactPHP. Therefore, a small bridge can be used intermediately)

Since fibers deal with the async part, you can write your Request handlers is if they were synchronous:

In order to fetch multiple simultaneous requests, you can execute these in parallel:

If your client is fiber compatible, this will fetch all requests in parallel. If your client is not fiber compatible, this will result in the requests being performed in series.

SDK

In some situations, writing request handlers might be overkill. This package also provides some tools to compose a more generic API client instead. However, our primary suggestion is to create specific request handlers instead!

More information on creating SDKs

Testing HTTP clients

This tool provided some traits for unit testing your API client with PHPUnit.

UseHttpFactories

This trait can help you build requests and responses inside your tests without worrying what HTTP package you use:

UseHttpToolsFactories

This trait can help you build HTTP tools specific objects in unit tests. It could be hande to e.g. test transports.

Example:

UseMockClient

Includes UseHttpFactories trait

Preferably, this one will be used to test your own middlewares and transports. It is also possible to test a request-handler, but you'll have to manually provide the response for it.

example:

More info ...

UseVcrClient

Includes UseHttpFactories trait

This one can be used to test your request-handlers with realtime data. The first you use it in your test, it will do the actual HTTP request. The response of this request will be recorded and stored inside your project. The second time the test runs, it will use the recorded version.

example:

More info ...


All versions of http-tools with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.0 || ~8.3.0
ext-json Version *
azjezz/psl Version ^2.5
cardinalby/content-disposition Version ^1.1
league/uri Version ^7.3
php-http/client-common Version ^2.7
php-http/discovery Version ^1.19
php-http/httplug Version ^2.4
php-http/logger-plugin Version ^1.3
php-http/message Version ^1.16 || ^2.0
psr/http-client-implementation Version ^1.0
psr/http-factory Version ^1.0
psr/http-factory-implementation Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/http-message-implementation Version ^1.0
psr/log Version ^3
webmozart/assert Version ^1.11
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 phpro/http-tools contains the following files

Loading the files please wait ....