![]() |
How to use Phil Sturgeon's REST_SERVER - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to use Phil Sturgeon's REST_SERVER (/showthread.php?tid=36017) Pages:
1
2
|
How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]PaulDunn[/eluser] Hi I've followed the REST tutorial on nettuts: http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/ I can GET resources via a browser but when I try using curl command line it returns a 404. More importantly how do I go about sending a xml file to the Rest_sever so that user_post() accepts it and I can then process it? Sorry for multiple questions, just trying to get my head around this! Many thanks -Paul How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]smilie[/eluser] Hi, Please provide some PHP code, works easier. I have installed and am happy user of a RESTFull services by Phil. I do not work with XML but with json, however that should not matter for the REST itself. Also, you mentioned that you are using curl. My best guess is, because you are calling it from cron? Cheers, Smilie How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]PaulDunn[/eluser] Im just testing with the example code from the posted tutorial. When I access the resource from the browser with http://localhost/user/id/1 I get the expected output. When using curl from the osx terminal I get a 404 error. Im trying with: curl http://localhost/user/id/1 From what i've read that should be all I need for a simple GET request using curl. Also I dont know how to POST to this example api. By that I mean how can I test the post function with say xml or json. I cannot seem to get this working with curl. Code: require(APPPATH'.libraries/REST_Controller.php'); How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]smilie[/eluser] Hm, I think that with curl, you will have to specifically tell curl to do POST instead of GET. Code: smilie@smilie-desktop ~ $ curl --help | grep POST But that is from command line, do not know how it works from PHP (google it ![]() I am using (and recommending) REST Client library. Then you do: Code: $p_data = array('sth'=>'1'); or for get: Code: $p_data = array('sth'=>'1'); See: https://github.com/philsturgeon/codeigniter-restclient Hope this helps :-) Cheers, Smilie How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]PaulDunn[/eluser] OK so inorder to test the REST_server I should create another controller which uses the rest client library to post stuff to the server? How to use Phil Sturgeon's REST_SERVER - El Forum - 11-18-2010 [eluser]smilie[/eluser] Edit: Almost exaclty ![]() You just have to place rest client library (download it from preview post) and place it in the library directory. You can auto load it or not - and then do code bellow... Exactly. That is what I have done in any case. I have also placed both libraries in Core itself (not in application) because I have multiple applications running from same core - so I need only 1 instance of Rest server / client. Only thing I need to do then is: Code: $this->load->library('rest', array('server' => REST_SERVER)); You can use post / get and also different formats like json, xml... Cheers, Smilie How to use Phil Sturgeon's REST_SERVER - El Forum - 11-21-2010 [eluser]PaulDunn[/eluser] Hmm I cannot seem to get it working. My rest server: Code: class Api extends REST_Controller That works fine when accessed from a browser: http://localhost/index.php/api/property But when I use the client library I dont get any response: Code: class Test extends Controller Nothing happens when I browse to: http://localhost/index.php/test Any ideas? Thanks for all the help so far! ![]() How to use Phil Sturgeon's REST_SERVER - El Forum - 11-21-2010 [eluser]smilie[/eluser] Hi, Try this: Code: class Test extends Controller How to use Phil Sturgeon's REST_SERVER - El Forum - 11-21-2010 [eluser]PaulDunn[/eluser] Says page not found. I'm guessing that's because client library is adding query string variables? Is there a way to pass the information without using query strings? Cheers -Paul How to use Phil Sturgeon's REST_SERVER - El Forum - 11-21-2010 [eluser]smilie[/eluser] Do you meqn id =>1? Should make difference. Can you describe you local server configuration? Seems like your web server does not recognize localhost domain... |