imanaging-document/api-communication-bundle

Service de communication, par API, entre diverses applications

v2.0 2021-09-23 10:45 UTC

This package is auto-updated.

Last update: 2024-03-30 00:17:37 UTC


README

This bundle allows different imanaging-document applications to communicate with each other.

This bundle can't be used outside an imanaging-document application.

Install the bundle with:

$ composer require imanaging-document/api-communication-bundle

Configuration

You have to create a config/packages/imanaging_api_communication.yaml file:

imanaging_api_communication:
    project_dir: '%kernel.project_dir%'
    zeus_api_url: ~
    zeus_api_login: ~
    zeus_api_password: ~
    zeus_mock_dir: ~
    client_traitement: ~
    core_api_url: ~
    core_api_token: ~
    core_mock_dir: ~

Usage in services

Add a new argument to your service in your config/services.yaml file:

login:
    class: App\Service\MyBeautifulService
    arguments: [..., '@api_zeus_communication', ...]

Get the ApiZeusCommunication in your this way :

class MyBeautifulService
{
  private ...
  private $apiZeusCommunication;
  private ...
  
  /**
   * ...
   * @param ApiZeusCommunication $apiZeusCommunication
   * ...
   */
  public function __construct(..., ApiZeusCommunication $apiZeusCommunication, ...){
    ...
    $this->apiZeusCommunication = $apiZeusCommunication;
    ...
  }
  ...
}

Examples

GET example :

$url = '/my-beautiful-get-url';
$response = $this->apiZeusCommunication->sendGetRequest($url);

if ($response->getHttpCode() === 200) {
  // SOME LOGIC
}

POST example :

$postData = array(
  '...' => '...',
  'my_post_key' => $myPostValue,
  '...' => '...',
);

$url = '/my-beautiful-post-url';
$response = $this->apiZeusCommunicationService->sendPostRequest($url, $postData);

if ($response->getHttpCode() === 201) {
  // SOME LOGIC
}