PHP Classes
elePHPant
Icontem

PHP Silex REST Multi Lazy Load: Create REST APIs with module lazy loading

Recommend this page to a friend!
  Info   View files Documentation   View files View files (27)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2016-07-30 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 138 This week: 1All time: 8,254 This week: 1,047Up
Version License PHP version Categories
silex-rest-api-multi 1.0GNU General Publi...5PHP 5, Libraries, Web services
Collaborate with this project Author
Description

This package can be used to create REST APIs with module lazy loading.

It takes a configuration file that is loaded from the config directory and handles REST API requests using micro-service classes.

The package can route the requests and lazy-load service classes, i.e. on demand when the API requests are performed. It supports authentication of API users.

Innovation Award
PHP Programming Innovation award nominee
July 2016
Number 5


Prize: One ebook of choice by Packt
Many packages can implement APIs that map requests to classes that will handle the API requests.

Great part of those packages require that you create objects that will handle the API requests.

This package simplifies the process by just specifying the name of the modules that will handle the requests.

This way the package will only load the classes and create the necessary micro-service and controller objects when the respective API requests are received.

Manuel Lemos
Picture of John Diaz
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

Details

silex-rest-api-multi-lazyload

This is a SILEX based Rest API with module lazy load, it uses micro services and has authentication. It uses token authentication and is useful for Angularjs Applications, it also uses Yandex service to translate strings for internationalization.

This api can be used for exposing different web services, that means that every service can have its own workspace and database configuration, it is built in a modular fashion, where removing any part won't affect the whole functionality.

Api Refecence

https://secureaudit.co/api-docs

For multiple API interfaces, just create a new dir:

public2/
.htaccess
index.php

.htaccess file contents:

 #Options -MultiViews
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [L]

index.php contents:

 require_once __DIR__ . '/../vendor/autoload.php';
 $app = App\Rest::run('prod2');

Create a prod2.php config file under ./config/

_About the Lazy Load._

This rest API uses lazy loading for services, it has a Factory pattern implemented so all naming conventions must be kept for controllers and services.

Do the following to run:

composer install 
php -S 0:8001 -t public1/

Run tests:

 vendor/bin/phpunit 

Point to:

 http://localhost:8001/api/v1/whatever

HTTP Request Headers:

 'Content-Type: application/json'
 'x-token: your-auth-token'

License see LICENSE file.

Authentication method:

curl -i -H "x-requested-with: CLFYf7yz1it9x16FX1b5rlDNp3qkXJWB" -H "Content-Type: application/json" -X-POST http://localhost:8001/api/v1/login -d '{
  "login": { "email": "test@example.com", "pass": $apiPass //"04fbd445b467cf8679232accbcedf6192070d068"}
}'

How to generate passwords

$appKey  = 'CLFYf7yz1it9x16FX1b5rlDNp3qkXJWB';
$pass    = sha1('User123!*?'); //43e1eeda52d762652c2846badea1dd6a2a761d81
$apiPass = sha1($appKey.$pass); //04fbd445b467cf8679232accbcedf6192070d068

Login Headers, company token:

'x-requested-with: CLFYf7yz1it9x16FX1b5rlDNp3qkXJWB'
'Content-Type: application/json'

I owe you unit tests, sorry, test writers are welcome!!, any questions just contact me.

  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagedb (1 file)
Files folder imagepublic1 (2 files)
Files folder imagesrc (1 directory)
Accessible without login Plain text file .gitignore Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:138
This week:1
All time:8,254
This week:1,047Up