GithubHelp home page GithubHelp logo

bjeavons / rest_router Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mhrabovcin/rest_router

0.0 2.0 0.0 213 KB

Drupal 7 REST router for managing public non-drupal specific APIs.

PHP 100.00%

rest_router's Introduction

REST Router

Module that allows to create multiple REST endpoints defined in code. No UI is included in this module. Key features:

  • lightweight
  • supports versions of API with plugins
  • authentication plugins
  • routing to objects

Using router

To create new rest endpoint module needs to implement hook_rest_endpoints. Hook documentation is available in rest_router.api.php.

Custom responses

Object or function callbacks called by rest_router module can return response in different data formats. Scalar responses are always converted to array

    function my_callback() {
        return "value";
    }

Will become in response data

    array("value")

If other than 200 OK response is required function can return one of response defined response objects.

  • new RestRouterResponse($code, $data = NULL)
  • RestRouterErrorResponse($code, $message, $data = NULL)
  • RestRouterRedirectResponse($path, $code)

Each response has helper method that can be used from inherited class.

Examples

    public function myMethod() {
        // Custom response by initializing class
        return new RestRouterResponse(204);

        // Response by internal helper
        return $this->errorResponse(400, "Missing param [1]");

        // Redirect response example
        return $this->redirectResponse('method/2');
    }

Ideas

  • Allow API version definition to override 'auth', 'request', 'response' settings.

Tests

Unit tests are for classes. To run them

drush test-run "Rest Router Unit"

Web test cases can be run by

drush test-run "Rest Router"

rest_router's People

Contributors

mhrabovcin avatar bjeavons avatar andrewyang avatar gcassie avatar

Watchers

 avatar James Cloos 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.