-1

I have a "web app" on azure with laravel framowork. If I create the REST API using the "api management service" in php, how do I retrieve them from laravel? It's possible?

1 Answer 1

0

Yes, it's possible.

As Laravel doesn't have any built-in HTTP request package you may consider the following options to retrieve data from REST API.

  • cURL

  • file_get_contents

    $data = json_decode(file_get_contents('https://url_to_the_api'));
    
  • Guzzle

    $client = new \GuzzleHttp\Client();
    $res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
    echo $res->getStatusCode();
    // 200
    echo $res->getHeaderLine('content-type');
    // 'application/json; charset=utf8'
    echo $res->getBody();
    // '{"id": 1420053, "name": "guzzle", ...}'
    
    // Send an asynchronous request.
    $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
    $promise = $client->sendAsync($request)->then(function ($response) {
        echo 'I completed! ' . $response->getBody();
    });
    $promise->wait();
    

I personally prefer to use the Guzzle which can easily integrate with Laravel, you can check out @Mohammed Safeer's answer for details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.