PHP Classes

PHP API Server: Route requests to API calls to handler classes

Recommend this page to a friend!
  Info   View files Example   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 550 All time: 5,502 This week: 96Up
Version License PHP version Categories
php-api-server 1.1GNU General Publi...5.4PHP 5, Web services
Description 

Author

This class can route requests to API calls to handler classes.

It takes as parameters the name of an API call being invoked by a client via HTTP and an array of request parameters.

If the called API function is named Describe, the router class loads a class named Describe from the API directory path and makes the request be handled by that class.

For other API calls, the name of the call up to the / character defines the class that will handle the API call.

The name in front of the first / character defines the API call function name that is invoked on the API call handler class.

The router class checks first if a class file exists with that class name and loads it in that case. The router class also checks if the handler class also has a function with the invoked name before calling that handler class function.

API call error responses are returned in JSON encoded format.

Picture of Ettore Moretti
  Performance   Level  
Name: Ettore Moretti is available for providing paid consulting. Contact Ettore Moretti .
Classes: 12 packages by
Country: Italy Italy
Age: ???
All time rank: 107741 in Italy Italy
Week rank: 314 Up13 in Italy Italy Up
Innovation award
Innovation award
Nominee: 3x

Recommendations

What is the best PHP request routing class?
I want to route my PHP HTML templates for easy navigation

What is the best PHP api creation class?
i need to create api to be executed in multiple devices

Example

<?php
require_once ("config.php");
require_once (
CORE . "router.php");
require_once (
DB . "database.php");

// Recupero il get in una var separata per poter fare dei controlli di sicurezza (DA IMPLEMENTARE)
// Retrieve the get in a separate var to do security checks (BE IMPLEMENTED)
$req = $_GET;

// Controllo che il parametro api sia presente
// Check that the parameter APIs is present
if (isset ( $req ['api'] )) {
   
$api_request = $req ['api'];
    unset (
$req ['api'] );
} else {
   
print_r ( json_encode ( [
           
'Response' => '0',
           
'Error' => 'Request not available.'
            
] ) );
    exit ();
}
// Chiamata alla router class per risolvere la richiesta
// Call the router class to resolve the request
$my_router = new Router ( $api_request, $req );


Details

For more information go to: http://localhost/phpapiserver/ExampleUse

  Files folder image Files  
File Role Description
Files folder imagecore (1 file, 1 directory)
Files folder imagedb (1 file)
Files folder imageimg (2 files)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file config.php Conf. Class source
Accessible without login Plain text file index.php Example Class source
Accessible without login Plain text file README.txt Data Documentation

  Files folder image Files  /  core  
File Role Description
Files folder imageapi (4 files)
  Plain text file router.php Class Class source

  Files folder image Files  /  core  /  api  
File Role Description
  Plain text file API.php Class Class source
  Plain text file Describe.php Class Class source
  Accessible without login Plain text file Exampleuse.php Aux. Class source
  Plain text file User.php Class Class source

  Files folder image Files  /  db  
File Role Description
  Plain text file database.php Class Class source

  Files folder image Files  /  img  
File Role Description
  Accessible without login Image file flag-it.gif Icon Icon image
  Accessible without login Image file icon_flag_us_en.gif Icon Icon image

 Version Control Unique User Downloads Download Rankings  
 100%
Total:550
This week:0
All time:5,502
This week:96Up