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

[eluser]Phil Sturgeon[/eluser]
This is incredibly restrictive and in my mind not what REST is about. We have a brilliant solution at work that I will try and explain in a modular CI layout.

Blogs = Module name
API = Controller name
get_blogs = Method name

URI: /blogs/api/get_blogs/param1/value1/param2/name2

This uses an associative arrary to give you a little more flexibility. Your idea of extending a controller is brilliant. Name one REST_Controller and put it in a REST_Controller.php file in libraries that is included in your MY_Conroller file.

So far, its done nothing crazy or REST-like, its just a normal CI call.

What you'll want to do is create the ability to select different formats for your outputs.

The way we do it is to optionally set a var in the controller like so:

Code:
var $format = 'xml';

This will make the entire controller use a default format for output.

Then in the URL we accept extra params /format/xml, /format/json, etc. This can be checked in the REST_Controller() using:

Code:
$arguments = $this->uri->uri_to_assoc(4); // We are using a module name so we want it from the 4th not the 3rd as usual

if(array_key_exists('format', $arguments))
{
    $this->output_format = $arguments['format']
}[/code]

That way, your format is specified by the URL but if none is mentioned it will use the controllers.

I have yet to work out how you would actually commit the output as right now our models just return the data and it is passed to a static object to match the format type.

As I said our system is pretty spot on, but is done in native PHP and applying it to CI is a little more tricky.

Right now all you are doing is using normal Controller code and I assume you'll be making views for each REST controller you use. Your model is just another abstraction on the database ActiveRecord and that doesn't really make it as flexible as it should be.


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