2017 © Pedro Peláez
 

library rest-recipes

Collection of classes and scripts for REST apis

image

maikwoehl/rest-recipes

Collection of classes and scripts for REST apis

  • Monday, June 27, 2016
  • by maikwoehl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

rest-recipes

Router

Routes a request to specific endpoint and extracts variables., (*1)

A route must begin with '/'., (*2)

The order of the parameters of the route and the parameters of the routeFunction should be the same., (*3)

The order of routes must be in a order like:, (*4)

  • /recipe/
  • /recipe/create (e.g. default data and id as response)
  • /recipe/create/<name> (specific name for creation and id as response)
  • /recipe/<id>
  • /recipe/<id>/export
  • /recipe/<id>/<someVar>

Usage

<?php
/**
 * api.php
 *
 * @version 0.1
 *
 */

require_once "RestRecipes/autoload.php";

use RestRecipes\Router;

$app = new Router();

// Index
$app->route("/recipe/", "GET", function() {

});

// Detail
$app->route("/recipe/<id>", "GET", function($id) {

});

// Modify Object
$app->route("/recipe/<id>", "PUT", function($id, $data) {

});


try {
    $app->run();
} catch (RuntimeException $e) {
    // Show some information that no API endpoint was called
}

The default querySelector of the Router class is $q. You can call the api like this:, (*5)

GET api.php?q=/recipe/
GET api.php?q=/recipe/3

AuthenticationProvider

The AuthenticationProvider allows to check certain security options., (*6)

Usage

<?php
/**
 * api.php
 *
 * @version 0.1
 *
 */

require_once "RestRecipes/autoload.php";

use RestRecipes\Router;
use RestRecipes\AuthenticationProvider;

$security = new AuthenticationProvider(AuthenticationProvider::AUTH_HTTP_BASIC);
$app = new Router();


// Secure API route
$app->route("/secure/", "GET", function() {
    $security->setHttpBasicAuthenticationCredentials("user", "password");

    if (!$security->authenticate())
        return false;
});

// Index
$app->route("/recipe/", "GET", function() {

});

// Detail
$app->route("/recipe/<id>", "GET", function($id) {

});

try {
    $app->run();
} catch (RuntimeException $e) {
    // Show some information that no API endpoint was called
}

The Versions

27/06 2016

dev-master

9999999-dev

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

31/05 2016

0.1.6

0.1.6.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

31/05 2016

0.1.5

0.1.5.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

27/05 2016

0.1.3

0.1.3.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

27/05 2016

0.1.4

0.1.4.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

27/05 2016

0.1.2

0.1.2.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl

27/05 2016

0.1.1

0.1.1.0

Collection of classes and scripts for REST apis

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

by Maik Woehl