Download the PHP package mapado/rest-client-sdk without Composer

On this page you can find all versions of the php package mapado/rest-client-sdk. 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 rest-client-sdk

Rest Client Sdk StyleCI Scrutinizer

PHP Rest Client SDK for JSON API.

This client tries to avoid the complexity of implementing a custom SDK for every API you have. You just have to implements your model and a little configuration and it will hide the complexity for you.

installation

Usage

Imagine you have those API endpoints:

You will need to have two entities, let's say:

You will need to declare one Mapping containing your two ClassMetadata

Entity declarations

Configure an entity

Imagine the following entities:

Explanations

Entity definitions:

Attributes definition:

Relations definition:

UnitOfWork

EntityRepository has a UnitofWork used for PUT and POST requests. It sends only changed data not the full model by comparing with the entity stored on GET request.

Configuration

Using Symfony ?

There is a bundle to easily integrate this component: mapado/rest-client-sdk-bundle.

Once configured, you can get a client like this:

Not using Symfony

You need to configure client this way:

Optionnal: create a SdkClientRegistry

It can be easier to manager multiple clients. You can then call:

Accessing data

Fetching an entity / a list of entities

Creating a new instance

The persist operation will send a POST request with the serialized object to the API endpoint and return the newly created object

Updating an instance

The update operation will send a PUT request with the serialized object to the API endpoint (using the object Id) and return the updated object.

Deleting an instance

The remove operation will send a DELETE request to the API endpoint using the object Id.

Custom serialization

By default, when serializing, the SDK return only the Id to existing relations (like one-to-many).

You may want to serialize OneToMany relations though (imagine you have a Cart and you want to update linked cartItems)

to do so, you can specify a $serializationContext in the persist and update method:

Extending the repository

If you need to extend the EntityRepository, you can just do something like that:

Update your entity Rest attribute to let the entity be aware of it's repository:

Handling exceptions

The SDK will throw an Exception if your API return something different than a 2xx or a 404 status code.

You can see all the exceptions in this folder.

If you need to access the body of the response from your API you can do something like this:

PHPStan

rest-client-sdk does work well with PHPStan. See the related documentation.

Hacking

This library is tested on multiple Symfony and PHP version thanks to composer-test-scenarios.

But there is a conflict between ocramius/proxy-manager, composer 1&2, and php version.

In order to sort this issue, it may be usefull to update scenarios with this command for scenario with php 7.4:

This should be resolved with ocramius/proxy-manager#2.9.0 but it requires composer 2 absolutely, and we (Mapado) are not ready for this.

The path to fix this is to bump a major version with "ocramius/proxy-manager": "^2.9.0" that requires composer^2


All versions of rest-client-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/guzzle Version ^6.2.2 || ^7.5.0
friendsofphp/proxy-manager-lts Version ^1.0
symfony/http-foundation Version ^4.4 || ^5.0 || ^6.0
symfony/property-access Version ^4.4 || ^5.0 || ^6.0
psr/cache Version ^1.0 || ^2.0 || ^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 mapado/rest-client-sdk contains the following files

Loading the files please wait ....