Skip to content

Instantly share code, notes, and snippets.

@ibourgeois
Last active August 2, 2021 06:55
Show Gist options
  • Save ibourgeois/c5a7ae9d17df695401aa to your computer and use it in GitHub Desktop.
Save ibourgeois/c5a7ae9d17df695401aa to your computer and use it in GitHub Desktop.
Bridging Laravel 5 and Lumen with Guzzle
<?php
// Obviously, you would build up the request somewhere other than a route...
Route::get('/api', function()
{
$client = new \GuzzleHttp\Client();
$response = $client->get('http://path/to/api');
return $response->getBody();
});
// Visiting '/api' would return "Hello World" from Lumen!
<?php
$app->get('/text', function()
{
return 'Hello World';
});
// You may need to enable CORS header if Laravel and Lumen are on separate servers!
$app->get('/json', function() use ($app)
{
return response()->json([
"foo" => 'bar'
])
->header('Access-Control-Allow-Origin', '*');
});
@ibourgeois
Copy link
Author

You would also need to run 'composer require guzzlehttp/guzzle' on your Laravel app first.

@xmush
Copy link

xmush commented Aug 22, 2020

You would also need to run 'composer require guzzlehttp/guzzle' on your Laravel app first.
cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment