A little library to interact with any Rest API.
composer require kirianmurgadella/restapimanager
Create a new instance of ApiManager using its factory.
$apiManager = ApiManagerFactory::create('https://api-url.com');
This package works with: JSON Web Token and HTTP Basic Authentication
$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);
$credentials = [
'username' => 'myusername',
'password' => 'mypassword'
];
$auth = Auth\AuthFactory::create('basic', $credentials);
$apiManager = ApiManagerFactory::create('https://api-url.com', $auth);
$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']);
Every response will have the same structure
[
'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.
1.3.0
- Added Http Basic Authentication
1.2.0
- Fixed ApiManagerFactory namespace.
- Fixed ApiManagerFactory uses.
1.1.0
- Added DELETE method.
1.0.0
- Basic API interaction (GET, POST, PUT).
- Implemented JSON Web Token authentication.