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

[eluser]Yorick Peterse[/eluser]
So I am working on a REST API for an application of mine. Since this is the first time I'm making a REST API I'd like to receive some critique and tips. Right now my API controller looks like the following piece of code:

Controller

Code:
<?php
class Api extends Controller {
    
    // Constructor function
    function __construct() {
    parent::Controller();
    }
    /**
     * 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() {
    
    }
    
    // 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
    if(isset($codes[$status])) {
        // Return the response code
        return $codes[$status];
    }    
    }
    
    // Function to flush all data
    private function flushData() {
    
    }
    
    // Function to verify the request
    private function verifyRequest() {
    
    }
}
?>

Model

Code:
<?php

class Model_api extends Model {
    
    // Constructor function
    function __construct() {
    parent::Model();
    }
    // Function to output data in XML or JSON
    function getData($table,$id,$format) {
    
    }
    
    // Function to store the data that was sent using an HTTP request.
    function postData($table,$data) {
    
    }
    
    // Function to update existing data
    function putData($table,$id,$data) {
    
    }
    
    // Function to delete data
    function deleteData($table,$id) {
    
    }
}
?>

Keep in mind that the controller looks really rough and will most likely be changed a billion times. However, what I'm asking of you is to look at it and give any information that could be useful, finding the right info about REST is quite hard.


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