2017 © Pedro Peláez
 

library rip

Simple PHP REST framework

image

racler-productions/rip

Simple PHP REST framework

  • Saturday, June 30, 2018
  • by Racler Productions
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

REST in PHP - RIP

Content

  • Installation
  • Set up
  • Examples
  • Tips
  • License

Installtion

Install RIP with Composer: composer require racler-productions/rip, (*1)

Set up

First of all you need to Initialize the Rip class $rip = new Rip(); Then you can access the resource methods you want. Make sure that you have set up an htaccess file that forwards the requests to the application. For example:, (*2)

DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

Examples

GET

$rip->get("/user/:name/profile/picture", array("name"), $authFilter, function($parameters){
    echo 'Welcome ' . $parameters["name"];
});

Path parameters are marked with a colon :., (*3)

POST

$rip->post("/user/profile/picture", array("imageUrl", "userId"), $authFilter, functions($parameters){
    //Handle the request
});

PUT

$rip->put("/user/profile/picture", array("imageUrl", "userId"), $authFilter, functions($parameters){
    //Handle the request
});

DELETE

$rip->put("/user/profile/picture", array("userId"), $authFilter, functions($parameters){
    //Handle the request
});

Filter

The filter is a function that is called before the actual function is executed. A simple authentication filter could look like this:, (*4)

$authFilter = function(){
    $token = //get token from header
    if($this->tokenIsVald($token)){
        return $token
    }else{
        //Handle invalid token
    }
};

Tips

  • Resources that are often used are best placed at the beginning of the application.
  • No other output before usage.
  • After completion of each RIP function, prevent further execution.

License

Copyright 2018 Racler Productions, (*5)

MIT, see LICENSE for details, (*6)

The Versions

30/06 2018

dev-master

9999999-dev https://racler.productions/

Simple PHP REST framework

  Sources   Download

MIT

The Requires

  • php ^5.4.0 || ^7.0

 

by Tim Stachorra

api rest web service

30/06 2018

dev-develop

dev-develop https://racler.productions/

Simple PHP REST framework

  Sources   Download

MIT

The Requires

  • php ^5.4.0 || ^7.0

 

by Tim Stachorra

api rest web service