Phil Sturgeon's REST Client: help posting to REST server |
[eluser]cgeisel[/eluser]
Hi all, I'm new to CI and using Phil Sturgeon's REST Client & Server libraries, but I'm having a really hard time getting the client to POST correctly. I'm using his REST Server code exactly as written. The service is located here: http://test.christophergeisel.com/restserver/ Here's my REST Client: Code: class Newtest extends Controller When I set the method to 'get', the uri is set to 'index.php/example_api/user/id/1'. That works fine! If I set the method to 'post', the uri is set to 'index.php/example_api/user', and I send an array as the parameters, in this case: array('name' => 'Phil'); That gets me a response, but the 'name' parameter isn't set. Here's the code from the REST Server library, in example_api.php: Code: function user_post() Can anyone give me a hand here? I don't understand why my parameter isn't being received by the server, and I'm stumped. Shouldn't $this->post('name') get the value of 'name' from my parameter array? I'm confused. I also took a look at the file test.php that Phil includes with his REST Client code. He unserializes the parameters before sending them, but otherwise I think his technique is the same. Any help is much appreciated. I've been staring at this code for so long, I'm probably missing something obvious.
[eluser]cgeisel[/eluser]
Victory! It's what I suspect is a bug in the example_api.php REST_Controller. This method: Code: $this->post() ... doesn't seem to be an alias for $this->input->post() after all. When I changed my example_api.php code to: Code: function user_post() It started receiving the POSTed parameters correctly. Whew! I post my solution here in case anyone else runs into a similar problem. I've also opened an issue in the REST Client github site. I'll post back here if the author has any feedback.
[eluser]lerva[/eluser]
THANK YOU! I had this exactly same problem. Let's hope that Phil fixes his examples. Those are great libraries by the way!
[eluser]alexanderm[/eluser]
I'm having a really hard time with the client. My server is responding nicely to get requests, but I need to run other requests against it. Duh, right? How else can I see if my REST service works? How can I get my client to send "CodeIgniter-esque" urls? All I'm doing is: Code: function index() $this->rest->debug() says that my request is: http://<ip addr>/dev/alpha/index.php/api/user?id=11 and my server responds with a 404. How can I make the REST client send the get as .../user/id/11 ??? This all wouldn't be so bad if I could get my server to allow either query strings or CI-esque URLs, but I set $config['enable_query_strings'] = TRUE; in config.php, and my server still won't respond to query strings. It returns a 404. The REST framework never sends the request to my controller. Please help.
[eluser]alexanderm[/eluser]
[quote author="cgeisel" date="1275645734"]Victory! It's what I suspect is a bug in the example_api.php REST_Controller. This method: Code: $this->post() ... doesn't seem to be an alias for $this->input->post() after all. When I changed my example_api.php code to: Code: function user_post() It started receiving the POSTed parameters correctly. Whew! I post my solution here in case anyone else runs into a similar problem. I've also opened an issue in the REST Client github site. I'll post back here if the author has any feedback.[/quote] I have to second this post after spending some time scratching my head. $this->post('name'); does not return the name. $this->input->post('name'); returns the name. Still love the REST_Controller.
[eluser]lerva[/eluser]
[quote author="alexanderm" date="1277496536"]I'm having a really hard time with the client. My server is responding nicely to get requests, but I need to run other requests against it. Duh, right? How else can I see if my REST service works? How can I get my client to send "CodeIgniter-esque" urls? All I'm doing is: Code: function index() $this->rest->debug() says that my request is: http://<ip addr>/dev/alpha/index.php/api/user?id=11 and my server responds with a 404. How can I make the REST client send the get as .../user/id/11 ??? This all wouldn't be so bad if I could get my server to allow either query strings or CI-esque URLs, but I set $config['enable_query_strings'] = TRUE; in config.php, and my server still won't respond to query strings. It returns a 404. The REST framework never sends the request to my controller. Please help.[/quote] Drop the array and just use: $user = $this->rest->get('user/id/11', array(), 'json');
[eluser]xtcsonik[/eluser]
Thanks. Have it pretty much memorized but haven't been able to figure this one out. |
Welcome Guest, Not a member yet? Register Sign In |