PHP Classes
elePHPant
Icontem

PHP API Framework: Handle API requests with annotated classes

Recommend this page to a friend!
  Info   View files Documentation   View files View files (85)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-03-21 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 208 All time: 8,167 This week: 372Up
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.

Recommendations

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

  Performance   Level  
Name: Natanael Simões <contact>
Classes: 3 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

 

Details

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  
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

  Files folder image Files  /  docs  
File Role Description
Files folder imageclasses (6 files)
Files folder imagecss (5 files, 1 directory)
Files folder imagefiles (10 files, 1 directory)
Files folder imagefont (1 file)
Files folder imagegraphs (1 file)
Files folder imageimages (12 files, 1 directory)
Files folder imagejs (10 files, 1 directory)
Files folder imagenamespaces (3 files)
Files folder imagereports (3 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  docs  /  classes  
File Role Description
  Accessible without login HTML file PhpApi.Annotations.Api.html Doc. Documentation
  Accessible without login HTML file PhpApi.Annotations.HttpMethod.html Doc. Documentation
  Accessible without login HTML file PhpApi.ApiTrait.html Doc. Documentation
  Accessible without login HTML file PhpApi.PhpApi.html Doc. Documentation
  Accessible without login HTML file PhpApi.Route.html Doc. Documentation
  Accessible without login HTML file PhpApi.Token.html Doc. Documentation

  Files folder image Files  /  docs  /  css  
File Role Description
Files folder imagephpdocumentor-clean-icons (2 files, 1 directory)
  Accessible without login Plain text file bootstrap-combined.no-icons.min.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.min.css Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.css Data Auxiliary data
  Accessible without login Plain text file prism.css Data Auxiliary data
  Accessible without login Plain text file template.css Data Auxiliary data

  Files folder image Files  /  docs  /  css  /  phpdocumentor-clean-icons  
File Role Description
Files folder imagefonts (2 files)
  Accessible without login Plain text file lte-ie7.js Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  docs  /  css  /  phpdocumentor-clean-icons  /  fonts  
File Role Description
  Accessible without login Plain text file phpdocumentor-clean-icons.dev.svg Data Auxiliary data
  Accessible without login Plain text file phpdocumentor-clean-icons.svg Data Auxiliary data

  Files folder image Files  /  docs  /  files  
File Role Description
Files folder imageAnnotations (2 files)
  Accessible without login HTML file Annotations.Api.html Doc. Documentation
  Accessible without login HTML file Annotations.HttpMethod.html Doc. Documentation
  Accessible without login HTML file ApiTrait.html Doc. Documentation
  Accessible without login Plain text file ApiTrait.php.txt Doc. Documentation
  Accessible without login HTML file PhpApi.html Doc. Documentation
  Accessible without login Plain text file PhpApi.php.txt Doc. Documentation
  Accessible without login HTML file Route.html Doc. Documentation
  Accessible without login Plain text file Route.php.txt Doc. Documentation
  Accessible without login HTML file Token.html Doc. Documentation
  Accessible without login Plain text file Token.php.txt Doc. Documentation

  Files folder image Files  /  docs  /  files  /  Annotations  
File Role Description
  Accessible without login Plain text file Api.php.txt Doc. Documentation
  Accessible without login Plain text file HttpMethod.php.txt Doc. Documentation

  Files folder image Files  /  docs  /  font  
File Role Description
  Accessible without login Plain text file fontawesome-webfont.svg Data Auxiliary data

  Files folder image Files  /  docs  /  graphs  
File Role Description
  Accessible without login HTML file class.html Doc. Documentation

  Files folder image Files  /  docs  /  images  
File Role Description
Files folder imageiviewer (8 files)
  Accessible without login Image file apple-touch-icon-114x114.png Icon Icon image
  Accessible without login Image file apple-touch-icon-72x72.png Icon Icon image
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file custom-icons.svg Data Auxiliary data
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Image file hierarchy-item.png Icon Icon image
  Accessible without login Image file icon-class-13x13.png Icon Icon image
  Accessible without login Plain text file icon-class.svg Data Auxiliary data
  Accessible without login Image file icon-interface-13x13.png Icon Icon image
  Accessible without login Plain text file icon-interface.svg Data Auxiliary data
  Accessible without login Image file icon-trait-13x13.png Icon Icon image
  Accessible without login Plain text file icon-trait.svg Data Auxiliary data

  Files folder image Files  /  docs  /  images  /  iviewer  
File Role Description
  Accessible without login Image file grab.cur Data Auxiliary data
  Accessible without login Image file hand.cur Data Auxiliary data
  Accessible without login Image file iviewer.rotate_left.png Icon Icon image
  Accessible without login Image file iviewer.rotate_right.png Icon Icon image
  Accessible without login Image file iviewer.zoom_fit.png Icon Icon image
  Accessible without login Image file iviewer.zoom_in.png Icon Icon image
  Accessible without login Image file iviewer.zoom_out.png Icon Icon image
  Accessible without login Image file iviewer.zoom_zero.png Icon Icon image

  Files folder image Files  /  docs  /  js  
File Role Description
Files folder imageui (1 directory)
  Accessible without login Plain text file bootstrap.min.js Data Auxiliary data
  Accessible without login Plain text file html5.js Data Auxiliary data
  Accessible without login Plain text file jquery-1.11.0.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.mousewheel.js Data Auxiliary data
  Accessible without login Plain text file jquery.smooth-scroll.js Data Auxiliary data
  Accessible without login Plain text file prism.min.js Data Auxiliary data

  Files folder image Files  /  docs  /  js  /  ui  
File Role Description
Files folder image1.10.4 (1 file)

  Files folder image Files  /  docs  /  js  /  ui  /  1.10.4  
File Role Description
  Accessible without login Plain text file jquery-ui.min.js Data Auxiliary data

  Files folder image Files  /  docs  /  namespaces  
File Role Description
  Accessible without login HTML file default.html Doc. Documentation
  Accessible without login HTML file PhpApi.Annotations.html Doc. Documentation
  Accessible without login HTML file PhpApi.html Doc. Documentation

  Files folder image Files  /  docs  /  reports  
File Role Description
  Accessible without login HTML file deprecated.html Doc. Documentation
  Accessible without login HTML file errors.html Doc. Documentation
  Accessible without login HTML file markers.html Doc. Documentation

  Files folder image Files  /  nbproject  
File Role Description
Files folder imageprivate (2 files)
  Accessible without login Plain text file project.properties Data Auxiliary data
  Accessible without login Plain text file project.xml Data Auxiliary data

  Files folder image Files  /  nbproject  /  private  
File Role Description
  Accessible without login Plain text file private.properties Data Auxiliary data
  Accessible without login Plain text file private.xml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageAnnotations (2 files)
  Plain text file PhpApi.php Class Class source
  Plain text file Route.php Class Class source
  Plain text file Token.php Class Class source

  Files folder image Files  /  src  /  Annotations  
File Role Description
  Plain text file Api.php Class Class source
  Plain text file HttpMethod.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesrc (2 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file index.php Aux. Auxiliary script
  Accessible without login Plain text file keys.json Data Auxiliary data

  Files folder image Files  /  tests  /  src  
File Role Description
  Plain text file Blog.php Class Class source
  Plain text file Contacts.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:208
This week:0
All time:8,167
This week:372Up