Coder Social home page Coder Social logo

jk / restserver Goto Github PK

View Code? Open in Web Editor NEW
12.0 5.0 8.0 926 KB

A PHP REST server for providing a very light-weight REST API. If you want color highlighting support for TextMate, look here: https://gist.github.com/1149076

Home Page: http://jacwright.com/blog/250/simple-rest-server-in-php-supports-json-amf/

License: MIT License

PHP 100.00%

restserver's Introduction

RestServer.php

Scrutinizer Code Quality Code Coverage Latest Stable Version License Total Downloads SensioLabsInsight Documentation Status

Master branch Develop branch
Master Build Status Develop Build Status

A PHP REST server for providing a very light-weight REST API. Very easy to set up and get going. Independent from other libraries and frameworks. Supports HTTP authentication. Supports AMF data if the Zend Framework is present for Flash clients.

As of Classification of HTTP-based APIs this implementation should be considered as an HTTP based type II type of an API. So it is not an academic version of a real RESTful API, but this is by intention, so it's easy to understand and install.

restserver's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar hkerem avatar jacwright avatar jk avatar nusphere avatar ocramleznem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

restserver's Issues

Implement automatic CORS support

WIP

To support AJAX requests from other sites, we want to implement CORS-support.

If a controller does not have an OPTIONS route, restserver should take care of this and make that endpoint available to send the adequate headers to enable browser's preflight requests.

Bug while sending params via POST with a valid Content-Type

That issue came up during the deployment of an AngularJS web app running within Firefox. The Firefox appended to the intended:

Content-Type: application/x-form-urlencoded

Header. A statement about the used encoding so it was sent as:

Content-Type: application/x-form-urlencoded; charset=UTF-8

which broke RESTServer, since it misinterprets the Content-Type thinking that the requester doesn't do a urlencoded, parametered request.

Generated documentation using a API description language

The source code as a documentation is fine if you're the only one who is using the API. But when you open up to third-party, the absence of a good documentation will render your API useless to others. Since jk/restserver manage its functionality via DocBlock comments it's straight forward to generate a comprehensive documentation from it.

I have something like http://swagger.io/ in mind. But other languages are already worth to consider.

Implement one or more of the following API specification/description languages:

Filter, sanitize and validate input variables

As of today, you can specify GET parameters as input to your methods. There is no standardized why to do so for other HTTP verbs like POST, PUT and DELETE. You have to parse $_POST etc. by your self.

While implementing a more user friendly why for accessing input variables it's a good idea to think about security. There is some work in this field. I want to implement some kind of a plugin architecture to integrate https://github.com/Wixel/GUMP to do the filtering etc.

I want to achive something like this chunk:

/**
 * Search
 * 
 * search for something
 *
 * @url POST /search
 * @url GET /search/$value
 * @validate value required, alpha_numeric, max_len=100, min_len=4
 * @filter value trim, sanitize_string
 */
public function search($value='')
{
    # code...
}

Authentication

Create an interface for authentication concerns. So that's easier to support OAuth2 frameworks and HTTP basic auth.

Methods with only optional params are improperly initialized

If you have a function, where all parameters are optional and you call it without any parameters, the parameters wouldn't initialized with their default values. Instead they get numbered default values (i.e. param1 โ†’ 0, param2 โ†’ 1).

/**
     * Unorderd params
     * @url GET /unorderd
     * @url GET /unorderd/$param1
     * @url GET /unorderd/$param2/test/$param1
     */
    public function unorderd($param1 = 'default', $param2 = 'default')
    {
        return array('param1' => $param1, 'param2' => $param2);
    }
  • Reproduce issue
  • Write unit tests covering this issue
  • Fix issue
  • Release new version number

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.