0

I have an application in Laravel5. What I need is to be able to call an external api and then process the response from the api accordingly.

The response I will get in return is in the form as an xml tag as follows with either True or False

<statusCheck success="true"/>

Can someone point me to the right direction that how can I call to external api?

Note Please note that I want to make this request within a controller or model.

1
  • 1
    Take a look at the package guzzle Commented Mar 10, 2015 at 10:34

2 Answers 2

2

Use GuzzleHttp to send the HTTP requests.

Download the package through composer:

"guzzlehttp/guzzle": "5.0.*@dev"

See the documetation on http://guzzle.readthedocs.org/en/latest/

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

3 Comments

I have now downloaded the package, the question is what is the best way to be able to expose this package in Laravel5. I don't want to use require obviously in Laravel5 to have access to library
Use class reference on the top of your controller class declaration. then create object of Client class. and that's it.
use GuzzleHttp\Client;
0
$client = new GuzzleHttp\Client(['base_uri' => 'https://foo.com/api/']);
$response = $client->request('GET', 'test');
$response = $client->request('GET', '/root');

return response()->download(public_path($response));

we have to user Guzzlehttp client plugin.

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.