Welcome Guest, Not a member yet? Register   Sign In
Working on a REST API, critique requested
#3

[eluser]Yorick Peterse[/eluser]
I know that right now it's still more like a regular CI call, but I already made some changes to the controller. Also note that I'm seperating the Api module from the other modules. In this case I have 3 modules, Flork, Profile and API.

The flork module is the module that shows stuff which can be viewed by everyone, the other 2 speak for themselves Wink

Code:
<?php
class Api extends Controller {
    // Variables
    private $format;
    
    // Constructor function
    function __construct() {
    // Load the parent constructor
    parent::Controller();

    // Set the format, this will be set to XML by default
    $this->format = strpos($_SERVER['HTTP_ACCEPT'],'xml') ? 'xml' : 'json';
    
    }
    /**
     * Main REST functions
     *
     * By adding these functions to the URL, Flork will determine what has to be executed.
     */
    
    // Function to add data
    function post() {
    
    }
    
    // Function to get data
    function get() {
    // Retrieve the information required to target the table
    $table     = $this->uri->segment(3);
    $id     = $this->uri->segment(4);
    
    $this->load->model('Model_api');
    $this->model_api->getData($table,$id,$this->format);
        
    }
    
    // Function to update data
    function put() {
    
    }
    
    // Function to delete data
    function delete() {
    
    }
    
    /**
     * General functions
     *
     * General functions, such as generating messages.
     */
    
    // Function to generate a response message
    private function sendResponse($status = '200',$body = '',$content_type = 'text/html') {
    
    }
    
    // Function to generate a HTTP response code, based on the $status variable defined in sendResponse()
    private function getResponseCode($status) {    
    // Create an array containing all response codes and their messages
    $codes = array (
        100 => 'Continue',
            101 => 'Switching Protocols',
            200 => 'OK',
            201 => 'Created',
            202 => 'Accepted',
            203 => 'Non-Authoritative Information',
            204 => 'No Content',
            205 => 'Reset Content',
            206 => 'Partial Content',
            300 => 'Multiple Choices',
            301 => 'Moved Permanently',
            302 => 'Found',
            303 => 'See Other',
            304 => 'Not Modified',
            305 => 'Use Proxy',
            306 => '(Unused)',
            307 => 'Temporary Redirect',
            400 => 'Bad Request',
            401 => 'Unauthorized',
            402 => 'Payment Required',
            403 => 'Forbidden',
            404 => 'Not Found',
            405 => 'Method Not Allowed',
            406 => 'Not Acceptable',
            407 => 'Proxy Authentication Required',
            408 => 'Request Timeout',
            409 => 'Conflict',
            410 => 'Gone',
            411 => 'Length Required',
            412 => 'Precondition Failed',
            413 => 'Request Entity Too Large',
            414 => 'Request-URI Too Long',
            415 => 'Unsupported Media Type',
            416 => 'Requested Range Not Satisfiable',
            417 => 'Expectation Failed',
            500 => 'Internal Server Error',
            501 => 'Not Implemented',
            502 => 'Bad Gateway',
            503 => 'Service Unavailable',
            504 => 'Gateway Timeout',
            505 => 'HTTP Version Not Supported'        
    );
    
    // Verify if the status message has been set and return it
    return (isset($codes[$status]) ? $codes[$status] : '');    
    }
    
    // Function to flush all data
    private function flushData() {
    
    }
    
    // Function to verify the request
    private function verifyRequest() {
    
    }
}
?>


Messages In This Thread
Working on a REST API, critique requested - by El Forum - 05-29-2009, 08:13 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:15 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:25 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:30 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:35 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:37 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:39 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:43 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:48 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 09:55 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 10:03 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 10:31 AM
Working on a REST API, critique requested - by El Forum - 05-29-2009, 12:45 PM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 03:53 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 05:10 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 05:29 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 08:27 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 08:28 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:21 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:26 AM
Working on a REST API, critique requested - by El Forum - 06-03-2009, 09:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB