PHP Classes

PHP API Framework: Handle API requests with annotated classes

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 219 All time: 8,284 This week: 74Up
Version License PHP version Categories
php-api 0.1.0MIT/X Consortium ...7Web services, PHP 7
Description 

Author

This package can handle API requests with annotated classes.

The main class can scan classes in a given directory and reads the annotations from the class source files to extract the list of functions and the API URL patterns that each function will handle.

The main class handles the API requests by dispatching the requests to the handler classes passing any parameters extracted from the request URL patterns.

Picture of Natanael Simões
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

 

Recommendations

Develop Webservice using PHP (Apache)
Develop Webservice using PHP (Apache). I need to program the ser

Documentation

PhpAPI

Create a API for your PHP project in minutes. Simple add an annotation to yours methods and "voilá": it's done.

Usage

/
 * @Api("my/route")
 * No @HttpMethod annotation, accepts all HTTP kinds of request methods
 */
public function myRoute() {
    // code
}

/
 * @Api("route/with/$var")
 * @HttpMethod("PUT") // will accept only PUT requests
 */
public function routeWith($var) {
    // code
}

/
 * @Api("another/$id/maybe/$var")
 * @HttpMethod("GET,POST") // will accept only GET and POST requests
 */
public function routeAnother($id, $var) {
    // code
}

As you can see, it uses a Symfony-like router to find the right code to execute. Moreover, it suports the use of patterns so some parts of request can be variables!

Just add a$ inside @Api value to make it act as a method parameter.

Installation

This library can be found on Packagist. We endorse that everything will work fine if you install this through composer.

Add in your composer.json:

{
    "require": {
        "ifroariquemes": "dev-master"
    }
}

or in your bash

$ composer require ifroariquemes/php-api

From any point, make available the following code to start:

require './vendor/autoload.php';
\PhpApi\PhpApi::start('src'); // your source code directory

If this script is available at http://example.com/api/v1/ (suposing you already have a router working previously) then the API router will understand things starting there: - http://example.com/api/v1/my/route - http://example.com/api/v1/route/with/me - http://example.com/api/v1/another/way/maybe/works

If you are not using a router, but created a new directory to keep our code, remember to enable mod_rewrite and have a file like this its root to get things done:

AddType application/x-httpd-php .php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
<Files "keys.json">
Order Allow,Deny
Deny from all
</Files>

This lib also uses a token system. You can activate it by creating a file named keys.json at API/project root folder:

{
    "SystemName": "token123456"
}

The client will use this token to communicate with the API by adding its value to the key X-API-KEY within the HTTP request header.

Docs & Contribution

You can also check the docs/ for futher information about the classes and stuff. All codes are well commented so fell free to go deep and help us get this even better.

Profit!


  Files folder image Files (85)  
File Role Description
Files folder imagedocs (2 files, 9 directories)
Files folder imagenbproject (2 files, 1 directory)
Files folder imagesrc (3 files, 1 directory)
Files folder imagetests (3 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:219
This week:0
All time:8,284
This week:74Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1544