Welcome Guest, Not a member yet? Register   Sign In
how to create twitter style API url..
#1

[eluser]Unknown[/eluser]
Hello,

I want to share how to create Twitter style API url.

twitter using API Url like this :
Code:
http://search.twitter.com/search.json?callback=foo&q=twitter

now we create this configuration
in application/config.php :

Code:
$config['uri_protocol']         = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
$config['controller_trigger']   = 'cxx';
$config['function_trigger']     = 'mxx';
$config['directory_trigger']    = 'dxx'; // experimental not currently in use

because i only need 1 controller using this, then i create this in my application/route.php
Code:
// Weather Services
$route['weather.json(.*)']   = "welcome/weather/json$1";
$route['weather.xml(.*)']    = "welcome/weather/xml$1";

// Location Based on CellID
$route['loc.json(.*)']       = "welcome/loc/json$1";
$route['loc.xml(.*)']        = "welcome/loc/xml$1";

then, in my controller as usually, i create function weather and loc like this :
Code:
function weather($type) {
    ..... rest of code .....

    switch($type) {
        case 'xml':
             $this->_outputXML();
             break;
        case 'json':
             $this->_outputJSON();
             break;
        default:
             $this->_error();
    }
}
function loc($type) {
    ..... rest of code .....

    switch($type) {
        case 'xml':
             $this->_outputXML();
             break;
        case 'json':
             $this->_outputJSON();
             break;
        default:
             $this->_error();
    }
}

and you can call the url http://your.server.url/weather.json?param and http://your.server.url/loc.json?param

that's it..

thanks
#2

[eluser]WanWizard[/eluser]
You need a patch that allows you to use segments for URI routing while not destroying the query string.

see http://ellislab.com/forums/viewthread/15...15/#768040
#3

[eluser]Unknown[/eluser]
[quote author="WanWizard" date="1280149851"]You need a patch that allows you to use segments for URI routing while not destroying the query string.

see http://ellislab.com/forums/viewthread/15...15/#768040[/quote]

Thanks WanWizard for correction..




Theme © iAndrew 2016 - Forum software by © MyBB