1. Go to this page and download the library: Download daniesy/rodels library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function index()
{
$users = Remote::users()->list();
return response()->json($users);
}
return [
/*
|--------------------------------------------------------------------------
| The remote API host
|--------------------------------------------------------------------------
|
| Set this value to the url of the remote API you want to connect to |
*/
'host' => env('RODELS_HOST'),
/*
|--------------------------------------------------------------------------
| The HTTP client used to send HTTP requests
|--------------------------------------------------------------------------
|
| This option defines the http client that rodels will be using to connect
| to the remote API.
|
| Supported: "curl"
*/
'client' => 'curl',
/*
|--------------------------------------------------------------------------
| The authentication method
|--------------------------------------------------------------------------
|
| You can set the authentication method that will be used when connecting
| to the API.
|
| Supported: "key"
*/
'auth' => 'key',
/*
|--------------------------------------------------------------------------
| Authentication configuration
|--------------------------------------------------------------------------
|
| Configure the key authentication method.
|
*/
'key' => [
'name' => 'api-key',
'value' => env('RODELS_KEY')
],
];
namespace App\Endpoints;
use App\Rodels\User;
use Daniesy\Rodels\Api\Components\Endpoint;
use Daniesy\Rodels\Api\Components\RodelCollection;
use Daniesy\Rodels\Api\Exceptions\InvalidModelException;
class Users extends Endpoint
{
/**
* @param array $params
* @return RodelCollection
* @throws InvalidModelException
*/
public function list(array $params = []) : RodelCollection
{
$response = $this->authRequest()->get("users", $params);
return new RodelCollection($response, User::class);
}
/**
* @param string $name
* @return User
*/
public function find(string $name) : User
{
$response = $this->authRequest()->get("users", compact('name'));
return new User($response);
}
}