PHP Classes
elePHPant
Icontem

PHP JSON API Server: Handle REST API requests with functions in scripts

Recommend this page to a friend!
  Info   View files Documentation   View files View files (32)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-02-03 (2 years ago) RSS 2.0 feedStarStarStarStar 74%Total: 632 All time: 4,913 This week: 367Up
Version License PHP version Categories
server 1.0.0BSD License5PHP 5, Web services
Description Author

This package can handle REST API requests with functions in scripts.

It registers functions from scripts present in a given directory to handle API requests to function calls mentioned in annotation comments.

The responses of the requests are returned in JSON format.

The package also comes with JavaScript client code to simplify calls done to API servers using this package.

Innovation Award
PHP Programming Innovation award nominee
February 2017
Number 5


Prize: One ebook of choice by Packt
Nowadays PHP is used to implement APIs that serve mainly mobile applications. Implementing an API consists mainly of defining how PHP code will handle requests for different URL endpoints.

This package makes the process as simple as defining as specifying a directory that contains scripts for handling requests for each of the supported API endpoints.

Each endpoint script will be loaded and a function is called to handle the endpoint request and returns the response data to be returned to the calling client in JSON format.

The package also comes with a simple JavaScript library to make calls to an API implemented with this package.

Manuel Lemos
  Performance   Level  
Name: Cesar D. Rodas <contact>
Classes: 39 packages by
Country: Paraguay Paraguay
Innovation award
Innovation award
Nominee: 25x

Winner: 5x

Details

JSONful

JSONful is a framework which helps creating API servers.

Features

  1. Ease of use * It exposes regular PHP functions to the API, making it easy to integrate with any other framework and existing code. * It is easy to make cross domain requests ($server['public'] = true;) * The javascript client works out of the box and it's optimized for performance * The client concatenates many requests and sending it in a single HTTP request. * It has no dependency, and it can be used with WebPack or directly.

Installation

composer require jsonful/server

Usage

api.php

require __DIR__ . '/vendor/autoload.php';

$server new JSONful\Server(__DIR__ . '/apps');
$server->run();

apps/prime.php

/ @API("prime") */
function is_prime($number)
{
    if ($number <= 0) {
        return false;
    }
    $middle = ceil($number/2);
    for ($i = 2; $i <= $middle; ++$i) {
        if ($number % $i === 0) {
            return false;
        }
    }
    return true;
}

/ @API("ping") */
function ping() {
    return ['pong' => time()];
}

client.js

var client = new JSONful("https://api.myapp.net/");

client.exec("ping", function(err, response) {
  console.log(response); // {"pong": xxxx}
}
client.exec("prime", 99).then(function(response) {
  console.error(response); // false
});
  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .travis.yml 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

  Files folder image Files  /  src  
File Role Description
Files folder imageJSONful (3 files, 2 directories)

  Files folder image Files  /  src  /  JSONful  
File Role Description
Files folder imageClient (2 files)
Files folder imageSession (2 files)
  Plain text file Response.php Class Class source
  Plain text file RetryException.php Class Class source
  Plain text file Server.php Class Class source

  Files folder image Files  /  src  /  JSONful  /  Client  
File Role Description
  Plain text file Request.php Class Class source
  Plain text file Requests.php Class Class source

  Files folder image Files  /  src  /  JSONful  /  Session  
File Role Description
  Plain text file Native.php Class Class source
  Plain text file Storage.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageapps (6 files)
Files folder imagefeatures (11 files)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file SessionStorage.php Test Class source
  Accessible without login Plain text file SimpleTest.php Test Class source

  Files folder image Files  /  tests  /  apps  
File Role Description
  Accessible without login Plain text file error.php Aux. Auxiliary script
  Accessible without login Plain text file filter.php Aux. Auxiliary script
  Accessible without login Plain text file prime.php Aux. Auxiliary script
  Accessible without login Plain text file session.php Aux. Auxiliary script
  Accessible without login Plain text file simple.php Aux. Example script
  Accessible without login Plain text file two.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  features  
File Role Description
  Accessible without login Plain text file empty.json Data Auxiliary data
  Accessible without login Plain text file error.json Data Auxiliary data
  Accessible without login Plain text file internal-error.json Data Auxiliary data
  Accessible without login Plain text file multiple.json Data Auxiliary data
  Accessible without login Plain text file not-found.json Data Auxiliary data
  Accessible without login Plain text file preload-context.json Data Auxiliary data
  Accessible without login Plain text file preload-with-name.json Data Auxiliary data
  Accessible without login Plain text file preload.json Data Auxiliary data
  Accessible without login Plain text file preroute.json Data Auxiliary data
  Accessible without login Plain text file retry.json Data Auxiliary data
  Accessible without login Plain text file simple.json Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:632
This week:0
All time:4,913
This week:367Up
 User Ratings  
 
 All time
Utility:95%StarStarStarStarStar
Consistency:95%StarStarStarStarStar
Documentation:85%StarStarStarStarStar
Examples:-
Tests:90%StarStarStarStarStar
Videos:-
Overall:74%StarStarStarStar
Rank:160