-
-
Save ishukshin/90c091366aea10e40437 to your computer and use it in GitHub Desktop.
Bridging Laravel 5 and Lumen with Guzzle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', '*'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment