Skip to content

Instantly share code, notes, and snippets.

@dusta
Created October 16, 2020 12:01
Show Gist options
  • Save dusta/c9ab5cfa1029721fc0a3fd025e5d332e to your computer and use it in GitHub Desktop.
Save dusta/c9ab5cfa1029721fc0a3fd025e5d332e to your computer and use it in GitHub Desktop.
api call to microservice - dframe
<?php
try {
$client = new Client();
$response = $client->request('GET', 'NAME_MICROSERVICE:80/SLUG');
$body = \GuzzleHttp\json_decode($response->getBody(), true);
$statusCode = $response->getStatusCode();
} catch (GuzzleException $e) {
return Response::renderJSON(['code' => 500, 'message' => $e->getMessage()])->status(500);
}
return Response::renderJSON(
[
'code' => $statusCode,
'message' => $body['message'] ?? '',
'data' => $body['data'] ?? []
]
)->status($statusCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment