| Recommend this page to a friend! | 
| Info | Documentation | Reputation | Support forum | Blog | Links | 
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2025-05-07 (Yesterday)  | Total: 219 | All time:  8,284 This week: 74 | ||||||
| Version | License | PHP version | Categories | |||
| php-api 0.1.0 | MIT/X Consortium ... | 7 | Web services, PHP 7 | 
| Description | Author  | |
This package can handle API requests with annotated classes.  | 
Develop Webservice using PHP (Apache)
Develop Webservice using PHP (Apache). I need to program the ser
Create a API for your PHP project in minutes. Simple add an annotation to yours methods and "voilá": it's done.
/
 * @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.
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.
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.
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Doc. | Documentation | |||
| / | docs | 
| / | docs | / | classes | 
| File | Role | Description | 
|---|---|---|
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
| / | docs | / | css | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
| / | docs | / | css | / | phpdocumentor-clean-icons | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Data | Auxiliary data | ||
|    | 
Doc. | Documentation | ||
|    | 
Data | Auxiliary data | ||
| / | docs | / | css | / | phpdocumentor-clean-icons | / | fonts | 
| File | Role | Description | 
|---|---|---|
|    | 
Data | Auxiliary data | 
|    | 
Data | Auxiliary data | 
| / | docs | / | files | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
|    | 
Doc. | Documentation | ||
| / | docs | / | files | / | Annotations | 
| File | Role | Description | 
|---|---|---|
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
| / | docs | / | images | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Icon | Icon image | ||
|    | 
Icon | Icon image | ||
|    | 
Icon | Icon image | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Icon | Icon image | ||
|    | 
Icon | Icon image | ||
|    | 
Data | Auxiliary data | ||
|    | 
Icon | Icon image | ||
|    | 
Data | Auxiliary data | ||
|    | 
Icon | Icon image | ||
|    | 
Data | Auxiliary data | ||
| / | docs | / | images | / | iviewer | 
| File | Role | Description | 
|---|---|---|
|    | 
Data | Auxiliary data | 
|    | 
Data | Auxiliary data | 
|    | 
Icon | Icon image | 
|    | 
Icon | Icon image | 
|    | 
Icon | Icon image | 
|    | 
Icon | Icon image | 
|    | 
Icon | Icon image | 
|    | 
Icon | Icon image | 
| / | docs | / | js | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
| / | docs | / | namespaces | 
| File | Role | Description | 
|---|---|---|
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
| / | docs | / | reports | 
| File | Role | Description | 
|---|---|---|
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
|    | 
Doc. | Documentation | 
| / | nbproject | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Data | Auxiliary data | ||
|    | 
Data | Auxiliary data | ||
| / | nbproject | / | private | 
| File | Role | Description | 
|---|---|---|
|    | 
Data | Auxiliary data | 
|    | 
Data | Auxiliary data | 
| / | src | 
| File | Role | Description | ||
|---|---|---|---|---|
|    | 
Class | Class source | ||
|    | 
Class | Class source | ||
|    | 
Class | Class source | ||
| / | src | / | Annotations | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
|    | 
Class | Class source | 
| / | tests | 
| / | tests | / | src | 
| File | Role | Description | 
|---|---|---|
|    | 
Class | Class source | 
|    | 
Class | Class source | 
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 100% | 
  | 
  | 
| User Ratings | ||||||||||||||||||||||||||||||
  | ||||||||||||||||||||||||||||||
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.