Giter VIP home page Giter VIP logo

krestful's Introduction

krestful

An enhanced RESTful interface for Kohana. This module extends existing Kohana Core classes to provide a more rigid RESTful interface that validates the following HTTP headers;

  • accept
  • accept-charset
  • accept-language

krestful validates the Request header and attempts to match the request accept declarations with the Restful_Controller accept options. Results are returned in order of match, sorted by quality.

In strict mode, if no matching type is found the appropriate HTTP_Exception will be thrown. Otherwise the Kohana defaults values will be used.

Usage

To use krestful, ensure the KRestful module is enabled within the Kohana application. Within the bootstrap.php module add the following:

 Kohana::$modules(array(
      'krestful'    => MODPATH.'krestful'
 ));

Note: This module modifies the inheritance tree for a number of Kohana Core classes. Ensure any inheritance conflicts are resolved within your application.

Once the krestful module is loaded, controllers can extend Controller_REST safely and receive the enhancements of this module.

The following properties can be set to the Restful_Controller class.

  1. Restful_Controller::$_accept Defines the acceptable types (mime) the controller supports. e.g. text/html, application/json, application/xml, ...
  2. Restful_Controller::$_accept_charset Defines the acceptable character sets the controller supports. e.g. utf-8, 'utf-16', 'ISO-8859-1', ...
  3. Restful_Controller::$_accept_lang Defines the acceptable languages the controller supports. e.g. en_US, en_GB, fr_FR
  4. Restful_Controller::$_accept_strict Defines if the controller will be strict and enforce on the defined acceptable arguments upon request.

The acceptable request parameters should be set in the controller definition. For example:

class Controller_Foo extends Controller_REST {

     protected $_accept = array(
          'text/html',
          'application/json',
          'application/xml'
     );

     protected $_accept_lang = array(
          'en_US',
          'en_GB'
     );

     protected $_accept_charset = array(
          'utf-8',
          'ISO-8859-1'
     );

     protected $_accept_strict = TRUE;
}

The following controller will only return either;

  • HTML, JSON or XML in
  • US or British English using
  • UTF-8 or ISO-8859-1 encoding

System Requirements

License

This software is protected by the ISC License.

Copyright (c) 2011, Sam de Freyssinet

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

krestful's People

Contributors

samsoir avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.