PHP Classes

PHP JSON RPC 2.0 Server: Handle to HTTP requests in JSON RPC v2.0 format

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 192 All time: 8,531 This week: 125Up
Version License PHP version Categories
jsonrpcserverv2 1.0.0GNU General Publi...5PHP 5, Web services, AJAX
Description 

Author

This package can handle to HTTP requests in JSON RPC v2.0 format.

It takes HTTP requests and handles them by calling functions loaded from scripts in a directory with file names based on the HTTP request URL parameters.

The class takes the return value of the called functions and returns them encoded in the JSON format.

The package comes with both JavaScript AJAX based and PHP clients to test a server using this class.

Picture of Chris Jeffries
  Performance   Level  
Name: Chris Jeffries <contact>
Classes: 6 packages by
Country: United Kingdom
Age: 75
All time rank: 2176101 in United Kingdom
Week rank: 587 Up20 in United Kingdom Up
Innovation award
Innovation award
Nominee: 3x

Example

<!DOCTYPE HTML>
<html>
    <head>
        <title>JSON-RPC Tester via Ajax</title>
        <script src='jsonrpcClient.js'></script>
        <script>
            window.addEventListener('load', function () {
                let btn = document.getElementById('btn');
                let txt = document.getElementById('txt');
                try {
                    btn.addEventListener('click', function (e) {
                        let request = JSON.parse(txt.value);
                        let p = jsonrpcClient('../index.php', request.id, request.method, request.params);
                        p.then(function (response) {
                            alert('ALL OK: ' + JSON.stringify(response, undefined, 4));
                        });
                        p.catch(function(response) {
                            alert('OH NO!: ' + JSON.stringify(response, undefined, 4));
                        });
                    });
                }
                catch (e) {
                    alert(e);
                }
               
            });
        </script>
    </head>
    <body>
        <h1>JSON-RPC Tester via Ajax</h1>
        <p>This tester fires off a JSON-RPC request to the server using
        a Javascript Ajax client in the file 'jsonrpc.js'</p>
        <textarea id=txt cols=50 rows=10>{
    "id":1,
    "method":"test",
    "params":{
        "p1":"one",
        "p2":"two"
    }
}
        </textarea>
        <br />
        <button type=button id=btn>Send!</buttpn>
    </body>
</html>


  Files folder image Files  
File Role Description
Files folder imagedocs (2 files)
Files folder imageexamples (4 files)
Files folder imagemethods (1 directory)
Accessible without login Plain text file index.php Example HTTP shim for server class
Plain text file jsonrpcServer.class.php Class class to implement server
Accessible without login Plain text file JSON_RPC.md Doc. Online readable documentation

  Files folder image Files  /  docs  
File Role Description
  Accessible without login Plain text file filelayout.txt Doc. File and directory layout
  Accessible without login Plain text file JSON_RPC.pdf Doc. Documentation (takes precedence over markdown version)

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file exampleViAjax.html Example HTML page to test using the AJAXclient
  Accessible without login Plain text file exampleViaPHP.php Example Example using the PHP CURL Client
  Plain text file jsonrpcClient.class.php Class Implements the PHP CURL Client
  Accessible without login Plain text file jsonrpcClient.js Data Implements the AJAX client (in ECMAScript6)

  Files folder image Files  /  methods  
File Role Description
Files folder imagetest (1 file)

  Files folder image Files  /  methods  /  test  
File Role Description
  Accessible without login Plain text file test.php Example Example method

 Version Control Unique User Downloads Download Rankings  
 0%
Total:192
This week:0
All time:8,531
This week:125Up