0

Hi there,
I want to make rest api in codeigniter .Already have created backend for web app.I need to fetch json data from third party(Request Response).Can you give me the idea how to integrate rest api in backend?

Edited by praba_web: mistook

3
Contributors
2
Replies
13
Views
1 Year
Discussion Span
Last Post by cereal
0

In addition: so what you're searching for is a client to query remote services? Have you considered Guzzle?

You can integrate it into CI3 by using composer:

composer require guzzlehttp/guzzle:~6.0

And modifying the composer_autoload variable in application/config/config.php into:

$config['composer_autoload'] = FCPATH . 'vendor/autoload.php';

Then in your controller you can do:

public function index()
{
    $client   = new \GuzzleHttp\Client();
    $response = $client->request('GET',
                                 'http://httpbin.org/get',
                                 ['timeout' => 5]);

    print $response->getStatusCode();
}

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.