bee4/transport

Transport client built around a simple API!

View project onGitHub

A new client, why not using something like Guzzle ??

This project is a simple transport client which is designed to perform calls using the same API regarding the protocol used. We previously use well known Guzzle client but we also need to perform FTP, FTPS, SFTP requests.

How to use it ?

This code is built around a fluent interface between the Client, the Request and the Response objects.

You first build a client and define if needed, the start URL point:

<?php $client = new \Bee4\Transport\Client('http://www.example.com'); ?>

Then you choose an implemented request type and call the client method :

<?php
  $request = $client->createRequest('GET', '/endpoint?param1=value'); //GET
  $request = $client->createRequest('POST', '/endpoint/save'); //POST
?>

If the request type requested does not exists or is not handled, an `Exception` is thrown.

<?php $request = $client->createRequest('TOTO', '/endpoint/save'); ?>

You can also use the `MagicHandler` with it request as a method API :

<?php
  //The magic handler use PHP __call method to attach specific
  //transport methods (GET, POST, DELETE) as method name
  $magic = new \Bee4\Transport\MagicHandler($client);
  $request = $magic->delete('/endpoint/id'); //DELETE
?>

Some requests need a body to be valid (POST, PUT, ...), you can fill the body with the help of the WithBodyTrait which is linked to theses objects:

<?php
  $request = $client
    ->createRequest('POST', '/endpoint/save')
    ->setBody('{ "id": 1, "name": "Arthur" }'); //POST
?>

The exact same code is used to perform all the requests, you just need to give your URL:

<?php
  //Downlad a FTP file
  $file = (new \Bee4\Transport\MagicHandler())
    ->get('ftp://serveur.com/file.zip')
    ->send()
    ->getBody();
?>

Authors and contributors

This project is built and maintained by @shulard. If you have any questions or issues, please feel free to add issues or submit pull request to this repository.

Support or Contact

Having trouble with this code? Contact dev@bee4.fr and we'll help you sort it out.