Restler 3.0

Just deal with your business logic in php, restler will take care of the REST!

Turn your classes and its methods into an easily usable and better Web citizen with Restler.

A RESTful API server framework that is written in PHP that aids your mobile / web / desktop applications. A framework, but with a difference – Restler is all here to bend and mend to your needs

Writing Server made easy and light. With the light weight, Restler makes writing a server as easy as writing it with just 3 PHP files

Restler’s advantage is the simplicity. You can create a PHP class with some functions to expose. If you know how to write object oriented PHP, then you already know how to use Restler. It’s action speaks for its effectiveness

Restler is all about being light and easy. All public methods are automatically mapped to a URL

Tailor-made Restler is known for the customization options. You just need to write class and add methods in PHP. It is just there!

Restler makes it effective and facilitates your customizing needs. It goes ahead to leverage your designing creativities. A plugin architecture is used

for supporting different formats like json, xml, yaml, amf, plist is used, which also means that you can add your own formats easily

for supporting different authentication schemes and you can add your own auth plugin

While designing your application, RESTful server makes use of the Web’s well known architecture to your benefit

You just need to simply declare the function as protected and add an authentication class

Most of all, an obvious benefit with Restler is, it is free and open sourced

78 comments

I did attend a seminar at Flash Camp Chennai, me as a PHP developer eagerly waiting for some useful tool to boost up my development work, i like your concept of ‘Restler’, when it is scheduled to go live

@Luracast :
It always breaks when you remove ksort because in my case $p is already build to default
var_dump($p) =>
array(2) {
[1]=>
NULL
[2]=>
NULL
}
So 0 (has no default value) is the only one inserting in array when building arguments(so at the end of the array)
So at the end of the foreach loop $p is set to :
array(3) {
[1]=>
NULL
[2]=>
string(7) “testApp”
[0]=>
string(9) “access3_2”
}

What is good but badly ordered 😉
For info : I have 3 args, the first one is mandatory, the two others are optional with default to null.

You are right! POST is better than passing it directly as a query string in the URL and there are better ways to secure the API. Here the purpose is to show how easy it is to implement your own security mechanism and to keep it simple enough to directly test it in Browser. We will soon add more complex and secure authentication examples

Another question. In the CRUD example – real cool example implementation, BTW – the PUT method breaks the restful spec pretty badly by not being idempotent[1]. Is that intentional? I would expect a PUT method to replace all items in the table.

1. Unable to change the HTTP status code to non-error status code like 201
2. CRUD example incomplete as there are no methods to replace all items in table
3. Unable to set versioning in the MIME type
4. There is no rfc2616 cache support

User guide with installation instruction will be released soon. But you need not wait for that, presentation at http://bit.ly/TakingCareOfTheREST walks you through the process. Also you can download the files and unzip them inside your localhost to try the examples yourself

thanks for the reply, I finally installed it on my server. However, I noticed some examples not working which you noted that it maybe due to .htaccess. I don’t have any htaccess on my server root, while my mod_rewrite is already enabled.

.htaccess file is available in every example folder but it may be hidden in your OS. Make sure you upload them. All examples should work with the index.php in the URL. You can try that by visiting the examples folder in the browser and test using the links provided (they include index.php in the URL)

Just started playing with Restler, and it elminates most of the plumming I don’t want to do when getting a REST API up and running. Nice.

And then, a small question:

Any plans for implementing support for replying with a proper WWW-Authenticate Digest header when a 401 is encountered? Seems the the current version is not quite flexible enough to accommodate that. I can always give take shot at a patching it myself, although I have no real experience with HTTP digest authentication. 🙂

Current version is already capable of doing Digest Authentication. In fact Restler 1.0 includes DigestAuthentication example which you can download from https://github.com/Luracast/Restler/zipball/v1.0.20 only change you need to make to that is change isAuthenticated function to __isAuthenticated to match change in the iAuthenticate interface in 2.0

Thanks for the quick reply. Glad you mentioned the return of associative array. BTW, I noticed when an Id doesn’t exists the response is false yet the HTTP status code is 200, any chance to change this to 401?

Specifying default value makes the parameter optional, function will receive the default value when it is not specified. In case of get($id=NULL) we return all records when the id is not specified, we return the specific record when id is specified.

I modified the simpleauth.php to support a un and an apikey. Kind of the start to where I need it to go, am going to just filter against a mysql database and ensure the username + apikey combo matches.

Thanks for that. But what I’m trying to here is validate the request by checking the Authorization header, am I wrong that HTTP_AUTH_KEY differs from header Authorization. My concern here is that Authorization header isn’t included in array of $_SERVER.

I’m using restler and i’m trying to implement some authentication by implementing iAuthenticate. The thing is, my authentication code needs to query my database to retrieve the user private key. this private key will always be provided in the url request.

I wanted to open just one database connection to each request. So i need to pass the db connection variable to my class that implements my authentication and to the other classes that handle all the requests. But i can’t figure it out how can i pass variables to my classes.. Is it possible?If yes how?

I’m looking at the simple BMI example and I have a question. I have modified the example and moved the bmi.php class file into a “classes” folder and the “restler” folder into a “lib” folder. When doing so and using spl_autoload_register(‘spl_autoload’) in “index.php” I get the following error:

Its a very nice piece of code , that you have created there arul. I wanted to know how to can i use this to to help me create an api that has to authenticate before accesing a resource. Like for example i want to access http://www.xyz.com/folder/impresource.csv

I also wonder how I should lay out “support files”… for example, if I have general helper functions in other classes/libs where should I put them? should I extend some class? etc? Any more complex examples?

I was able to get some nice auth working already! I can post some examples for ppl if anyone is interested…

1 – how do I switch output type? like XML or JSON? JSON is the most used standard anyhow, but some ppl might want to use XML occasionally? or other supported types? Would there be a way to implement something like http://site/API/mycall.json or /API/mycall.xml?

2 – to enable POST and GET on the same functions I can use the comments for routing method, and add a route for GET and a route for POST for the same function? (Do these comments configurations make ithe system any slower? thikning about large scalability)…

3 – Lowercase and Uppercase…whats the deal? in fucntion names, in file names, and in calls? Everything always lowercase except function names? Cant we use upper/lower to make things more readable?

4 – any example with file upload? or idea about it?

5 – is there any way to split the API files into further directories? Like /api/MODULE/FUNCTION I’d have 1 subdirectory for each MODULE, and one PHP for each FUNCTION? is something like this possible? adviseable?

Also, my system doesnt have spl_autoload, I havent been able to install it yet i plan to before production, but can you let me know the effects of this not being enabled? (I commented it).

About item 3, I realized that in the phpdoc mappings, camelCase does work! so it basically doesnt work just for the main class names…

Also, I’d like to understand a bit more about the files it includes, and such… I plan to have quite a few modules (classes) and dont want to load them all for all requests… want to load as few as possible to keep things quick…