RESTful API - Search & CRUD |
[eluser]Peng Kong[/eluser]
Here's my attempt at a REST Controller, your feedback is most appreciated. (see attached file) Features 1) Search and CRUD API 2) Query string for search (*query string must be enabled in config) 3) Decoupled from authentication library URLs 1) Search (GET Request) - http://api.mysite.com/users?one=1&two=2&...output=xml 2) [C]reate (POST Request) - http://api.mysite.com/users 3) [R]ead (GET Request) - http://api.mysite.com/users/1 4) [U]pdate (PUT Request) - http://api.mysite.com/users/1 5) [D]elete (DELETE Request) - http://api.mysite.com/users/1 Controller Template Code: <?php Credit goes to Phil Sturgeon http://philsturgeon.co.uk/news/2009/06/REST-implementation-for-CodeIgniter
[eluser]ortenheim[/eluser]
Hi i am testing your controller, while being new to REST services im not sure i set it up right... the places.php file i put in "application/controllers" and the REST_controller.php in "applciation/libraries" and rest.php. in the config.php i have set Code: $config['uri_protocol'] = "QUERY_STRING"; i get the error Quote:An Error Was Encounteredprobably since i dont put the right returning get functions: Code: $this->get('one'); im sorry i am really new to this My goal is to create a simple REST service that: 1. can POSTS a user to the database 2. can return the total amount of users in the database perhaps you can also make an example with a database with a model? or point me to where i can find such examples ![]() Also , how does one use authentication with the REST? ( i see you have included it in the create() function). Thank you in advance ![]()
[eluser]Peng Kong[/eluser]
Ok just do two things... 1) Change config Code: $config['uri_protocol'] = "PATH_INFO"; yep like you already did... enable query strings Code: $config['enable_query_strings'] = TRUE; 2) Sorry I missed this out... add the require line above into your controller Code: <?php check back tomorrow i'll try to come up with a simple working example also you should check out Phil Sturgeon's example... http://philsturgeon.co.uk/news/2009/06/R...odeIgniter
[eluser]Phil Sturgeon[/eluser]
The NetTuts tutorial on this finally got published. http://net.tutsplus.com/tutorials/php/wo...igniter-2/
[eluser]ortenheim[/eluser]
Been using your tutorial and creating my own get, works well with regular english characters but I have unicode characters like: Quote:äåö åæøin the database and when running "visitors" I get the error: Code: XML Parsing Error: undefined entity When displaying in regular pages the characters are showed correctly from the database. Model: Code: class Visitor_model extends Model Rest controller: Code: <?php How do i fix this unicode problem?
[eluser]Peng Kong[/eluser]
utf8_encode and urlencode your stuff. else they get messed up in url transit. look at my attached file you'll get the idea. yahoo twitter (and im sure other) apis all require you to do that before sending the data over url
[eluser]Peng Kong[/eluser]
oh crap sorry im not answering your question. sorry i read it wrong. what's inside your database? "& Ouml ;" (without spaceing) or Ö only the Ö is accepted in the url. urlencode it and get "% C3 % 96" (without spacing) before putting it in the url
[eluser]ortenheim[/eluser]
The letter Ö is in the database, not getting what you mean with url encoding? i am only opening the http://localhost:8888/restserver1/index....i/visitors that returns my database entries as an xml (included as one of the examples on nettuts)
[eluser]ortenheim[/eluser]
Also, what is also wierd is that when i remove the Ö and have O and the XML renders fine....when using http://localhost:8888/restserver1/index....ormat/html this errors is recieved.... ![]() Quote:A PHP Error was encountered
[eluser]Peng Kong[/eluser]
just to be clear you're using Phil's REST controller right (NOT the one downloaded from this page)? so im not lookin at the wrong file while helping you debug. try htmlentities($param) before pushing it to xml |
Welcome Guest, Not a member yet? Register Sign In |