2017 © Pedro Peláez
 

library restapimanager

Library to manage calls to a Rest API

image

kirianmurgadella/restapimanager

Library to manage calls to a Rest API

  • Monday, July 16, 2018
  • by kmurgadella
  • Repository
  • 3 Watchers
  • 0 Stars
  • 93 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Rest API Manager

A little library to interact with any Rest API., (*1)

Installation

composer require kirianmurgadella/restapimanager

How to use it

Initialize ApiManager

API without authentication

Create a new instance of ApiManager using its factory., (*2)

$apiManager = ApiManagerFactory::create('https://api-url.com');

API with authentication

This package works with: JSON Web Token and HTTP Basic Authentication, (*3)

Create a new instance for your authentication using its factory
With JWT
$credentials = [
    'email' => 'myemail@domain.com',
    'password' => 'mypassword'
];
$apiLoginUrl = 'https://api-url.com/login';
$apiTokenRequestUrl = 'https://api-url.com/request-token';
$auth = Auth\AuthFactory::create('jwt', $credentials, $apiLoginUrl, $apiTokenRequestUrl);
With BA
$credentials = [
    'username' => 'myusername',
    'password' => 'mypassword'
];
$auth = Auth\AuthFactory::create('basic', $credentials);
Create a new instance of ApiManager using its factory
$apiManager = ApiManagerFactory::create('https://api-url.com', $auth);

Use ApiManager

    $apiManager->get('api/get/endpoint', ['custom headers']);
    $apiManager->post('api/post/endpoint', ['request data'], ['custom headers']);
    $apiManager->put('api/put/endpoint', ['request data'], ['custom headers']);
    $apiManager->request('custom method', 'api/custom/endpoint', ['request data'], ['custom headers']);

Response

Every response will have the same structure, (*4)

[
    'status' => 'success/error',
    'statusCode => 'XXX',
    'data' => [],
    'errors' => [
        [...],
        [...],
        [...]
    ]
]
  • status: Contains success if everything goes well or error if something failed.
  • statusCode: Will be the HTTP Status from the cURL request.
  • data: It has the response of the request. Here is whatever you asked for.
  • errors: You want it empty, but at least it will tell you what failed.

Changelog

1.3.0, (*5)

  • Added Http Basic Authentication

1.2.0, (*6)

  • Fixed ApiManagerFactory namespace.
  • Fixed ApiManagerFactory uses.

1.1.0, (*7)

  • Added DELETE method.

1.0.0, (*8)

  • Basic API interaction (GET, POST, PUT).
  • Implemented JSON Web Token authentication.

The Versions

16/07 2018

dev-master

9999999-dev

Library to manage calls to a Rest API

  Sources   Download

The Requires

  • php >=7.0

 

by Kirian Murgadella

16/07 2018

1.2.0

1.2.0.0

Library to manage calls to a Rest API

  Sources   Download

The Requires

  • php >=7.0

 

by Kirian Murgadella

15/07 2018

1.1.0

1.1.0.0

Library to manage calls to a Rest API

  Sources   Download

The Requires

  • php >=7.0

 

by Kirian Murgadella

12/07 2018

dev-1.1.0-dev

dev-1.1.0-dev

Library to manage calls to a Rest API

  Sources   Download

The Requires

  • php >=7.0

 

by Kirian Murgadella

12/07 2018

1.0.0

1.0.0.0

Library to manage calls to a Rest API

  Sources   Download

The Requires

  • php >=7.0

 

by Kirian Murgadella

04/07 2018

1.1.0-alpha

1.1.0.0-alpha

Library to manage calls to a Restfull API

  Sources   Download

by Kirian Murgadella

04/07 2018

1.0.0-alpha

1.0.0.0-alpha

Library to manage calls to a Restfull API

  Sources   Download

by Kirian Murgadella