Download the PHP package tomb1n0/generic-api-client without Composer

On this page you can find all versions of the php package tomb1n0/generic-api-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 generic-api-client

Generic API Client

Latest Version on Packagist Total Downloads

When developing integrations for my PHP applications, i've often found myself carrying very similar but slightly different boiler-plate code around with me.

Often, each implementation will need:

There's also the question of what HTTP client to use, with the introduction of PSR-7, PSR-17 and PSR-18 we are able to depend on HTTP clients and factories that implement these interfaces rather than relying on any one client.

My goal with this package is to provide a wrapper around these PSR interfaces that makes it simpler to write API integrations.

Installation

Please note that this package does not require a HTTP client out of the box - but rather it depends on the virtual packages psr/http-client-implementation and psr/http-factory-implementation. This allows the package to be client-agnostic.

If you're unsure on this, i would recommend requiring guzzlehttp/guzzle alongside this package as it provides implementations for the above virtual packages.

If your project already require a HTTP-client that has implementations for the above standards, you can omit the guzzle dependency.

Usage

Please note that the examples below assume the use of Guzzle for the PSR-18 Client etc. Feel free to swap these out with your own.

Client Instantiation:

Making a JSON request:

Making a Form (x-www-form-urlencoded) request:

Making a request using a PSR-7 request directly

Configuration

Base Url:

Note that if you try to perform a request to a fully-formed URL that is different to the Base URL, the Base URL is ignored.

Pagination

You can create a pagination handler by creating a class that implements the PaginationHandlerContract interface provided by this package.

Middleware

Middleware can be created by creating a class that implements the MiddlewareContract interface.

Note that it is possible for a middleware to mutate the request before it is sent, or the response after it is received.

Testing the API

Stubbing Responses

It is possible to stub responses for testing purposes:

Preventing Stray Requests

By default the library will return a 200 OK for any non-matched responses when faked. If you prefer, you can prevent stray requests:

Asserting Requests

Maybe you want to assert the correct payload is sent to an API to create a user:

Asserting Requests With Custom Request Matching

Maybe you want to stub a response using some other information in the request

Do the same as above but use the stubResponseWithCustomMatcher method providing a custom implementation of the matcher contract. For example you could use the included UrlMatcher to check the method type

Running the Tests

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of generic-api-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
psr/http-client Version ^1.0
psr/http-message Version ^1.0|^2.0
psr/http-factory Version ^1.0
psr/http-client-implementation Version ^1.0
psr/http-factory-implementation Version ^1.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 tomb1n0/generic-api-client contains the following files

Loading the files please wait ....