opensmarty/rest-api-client

An elegant and smart Rest API Client with OAuth2 authentication support. Build for Laravel and Opensmarty Starter.

v1.0.1 2017-12-07 01:47 UTC

This package is auto-updated.

Last update: 2022-07-27 19:35:35 UTC


README

Latest Version Software License Total Downloads

Opensmarty Starter API Client is an elegant and smart Rest API Client with OAuth2 authentication support.

Build for Laravel and Opensmarty Starter.

It can be used for accessing APIs created using Opensmarty Starter framework.

Install

Via Composer

Install composer package to your laravel project

composer require opensmarty/rest-api-client

Add Service Provider to config/app.php

    'providers' => [
        ...
        Opensmarty\Rest\RestClientServiceProvider::class,
        ...
    ],

Publishing config file.

php artisan vendor:publish

After published, config file for Rest Client is config/rest-client.php, you will need to config it to use Rest Client.

Usage

$restClient = new \Opensmarty\Rest\RestClient('Opensmarty-starter');

$restClient->setOAuthUserCredentials([
    'username' => 'opensmarty@163.com',
    'password' => 'Abc12345',
]);
$restClient->withOAuthTokenTypeUser();

$response = $restClient->get("users")->getResponse();
if (!$restClient->isResponseStatusCode(200)) {
    $restClient->printResponseOriginContent();
    $responseMessage = $restClient->getResponseMessage();
    print_r($responseMessage);
} else {
    $responseData = $restClient->getResponseData();
    print_r($responseData);
}

Testing

phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.