CodeIgniter Forums
Codeigniter restclient not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: Codeigniter restclient not working (/showthread.php?tid=68647)



Codeigniter restclient not working - creawbe - 08-08-2017

I am trying to install the CodeIgniter RESTClient and RESTServer libraries for my solution. (philsturgeon-codeigniter-restclient and chriskacerguis-codeigniter-restserver ).
I managed to get the rest server up and running, but I am encountering issues with the rest client.
These are the steps I did to come where I am now:
  1. Copy the Rest.php file (downloaded from GitHub) and put it in the libraries folder

  2. Download the Curl library and put it in libraries

  3. Modified the code in Rest.php to uncomment 
    $this->_ci->load->library('curl'); (if I hover over the usages of the curl library in this file I get the following message):
Quote:Field 'curl' not found in CI_Controller

  1. 4. I create a new controller called "Restclient" to test my API. In this controller I created the following method:function rest_client_example($id){    $this->load->library('rest', array(        'server' => 'localhost/codeigniter/api/users/'    ));    $user = $this->rest->get('volunteer', array('id' => $id), 'json');    var_dump($user);}
[*]Browsing to http://localhost/codeigniter/api/restclient/rest_client_example/25 then gives me

Code:
D:\wamp\www\codeigniter\application\controllers\api\Restclient.php:36:null

[*]

When executing the following code instead of the above, I do get a correct result:

Code:
   $this->load->library('curl');

   $t = $this->curl->simple_get('api/users/volunteer', array('id'=>$id));
   var_dump($t);

[*]

So I do know that the curl is working.
My guess is that I am doing something wrong with the loading of the curl library in the restclient?


RE: Codeigniter restclient not working - jarmen_kell - 08-08-2017

Phil's RestClient lib is already autdated.
He doesn't involved in anymore PHP related projects at the moments.

regarding REST,
the best client for you to use to communicate with your Rest server is just by using CURL library
https://packagist.org/packages/curl/curl

install it with composer,
make sure your codeigniter already configured to work with composer's autoload.
https://www.codeigniter.com/user_guide/general/autoloader.html

then use it in your PHP's client.


RE: Codeigniter restclient not working - skunkbad - 08-08-2017

Like jarmen_kell suggests, you can just use cURL directly. Make your own library so you know how it works. cURL is super basic PHP, so have some fun with it.