2017 © Pedro Peláez
 

library descanse

Super-simple routing for PHP

image

joelalejandro/descanse

Super-simple routing for PHP

  • Friday, November 22, 2013
  • by joelalejandro
  • Repository
  • 5 Watchers
  • 22 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Descanse

A really really simple API framework for PHP., (*1)

The name

"Descanse" is the Spanish translation for "rest"., (*2)

Requirements

PHP >= 5.3.0, (*3)

Usage

  1. Add the .htaccess file included in this repository. This file redirects all incoming requests to a single dispatcher.
  2. Create a dispatcher file (i.e. index.php) that includes the Descanse core.
  3. Create a class that has the word "Service" as a suffix (UserService, SearchService, etc.).
  4. Create a method in that class with a name starting with get, post, put or delete (i.e. getUser, postUser, putUser, deleteUser, etc.). The method must return a PHP type, object or array.
  5. Include the Service class in the dispatcher (this is done automatically by default).
  6. Tell Descanse to run!

A Service Class example

, (*4)

 "Joel", "last" => "Villarreal");
  }
}
?>

, (*5)

The Dispatcher

, (*6)

, (*7)

Guidelines

  • Descanse creates routes automatically. Thus, UserProfileService becomes /userprofile/, and UserProfileService::getUserData() becomes GET /userprofile/userdata.
  • All methods within the Service class must be static.
  • All methods within the Service class must contain a $context argument, which contains an array with two keys: request (contains $_REQUEST data) and *args* (contains all of the slugs in the URL beyond the second slash, i.e. if the route is /userprofile/userdata/1/abc/3f, *args* will contain [0] => 1, [1] => abc, [2] => 3f).
  • All methods must start with get, post, put or delete.
  • If you wish to change the default settings of Descanse, you may do so using Descanse::$settings before Descanse::go().
  • The 'Accept' header defines the API method's output. If Accept is 'application/json', it'll automatically encode the data. More encoders are underway!

Settings

  • auto_register: true to search in all declared classes those whose name ends with "Service", false to allow manual registration. To do so, use the *Descanse::registerService($name)** method.

License

Descanse is licensed under the MIT License., (*8)

The Versions

22/11 2013

dev-master

9999999-dev http://github.com/joelalejandro/Descanse

Super-simple routing for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

routing simple web service