1. Go to this page and download the library: Download morcen/passage 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/ */
morcen / passage example snippets
Route::passage();
// config/passage.php
return [
'services' => [
// Forwards `GET http://{your-host}/github/users/morcen` to `GET https://api.github.com/users/morcen`:
'github' => [ // <-- This is the name of the service
'base_uri' => 'http://users-service/api/v1/', // <-- This is where the request will be forwarded to
// other options at https://docs.guzzlephp.org/en/stable/request-options.html
],
]
]
// app/Http/Controllers/Passage/GithubPassageController.php
use App\Http\Controllers\Controller;
use Illuminate\Http\Client\Response;
use Illuminate\Http\Request;
use Morcen\Passage\PassageControllerInterface;
class GithubPassageController extends Controller implements PassageControllerInterface
{
/**
* Transform and/or validate the request before it is sent to the service.
*
* @param Request $request
* @return Request
*/
public function getRequest(Request $request): Request
{
// Transform the request here
return $request;
}
/**
* Transform or validate the response before it is sent back to the client.
*
* @param Request $request
* @param Response $response
* @return Response
*/
public function getResponse(Request $request, Response $response): Response
{
// Transform the response here
return $response;
}
/**
* Set the route options when the service is instantiated.
*
* @return array
*/
public function getOptions(): array
{
return [
'base_uri' => 'https://api.github.com/',
];
}
}
// app/Http/Controllers/UserController.php
use Morcen\Passage\Facades\Passage
class UserController extends Controller
{
public function index()
{
$response = Passage::getService('github')->get('users/morcen');
return $response->json();
}
}