Download the source package:
http://www.slimframework.com/
Slim-based restful API Sample:
<?PHPrequire'/darjuan/slim/slim.php '; Use\slim\slim asSlim; Slim::Registerautoloader ();$app=NewSlim (Array( ' Debug ' =true, ' templates.path ' = './templates '));classbookserviceimpl{functionget_books_list () {$books=Array(); for($i= 0;$i< 10;$i++) { $book=Array(' sku_no ' = ' 9si0000 '.$i, ' book_name ' = ' php learning '); $books[$i] =$book; } return $books; }}classapiresponse{ Public functionShow$code,$msg,$data) { Header(' Content-type:application/json '); $response=Array( ' Code ' =$code, ' message ' =$msg, ' data ' =$data ); EchoJson_encode ($response); }}$app->get ('/books ',function(){ $books= Bookserviceimpl::get_books_list (); Apiresponse:: Show (' 200 ', ' Return to Success ',$books);});$app->get ('/books/:id ',function($id){ $books= Bookserviceimpl::get_books_list (); Try { $book=$books[$id]; } Catch(Exception $e) { $book=NULL; } if(Empty($book) ) {Apiresponse:: Show (' 404 ', ' Resource not present ',$book); return; } apiresponse:: Show (' 200 ', ' Return to Success ',$book);});$app->delete ('/books/:id ',function($id){ $books= Bookserviceimpl::get_books_list (); unset($books[$id]); Apiresponse:: Show (' 200 ', ' Return to Success ',$books);});$app->run ();
Slim-Ultra Lightweight PHP Restful API build Framework