PHP code example of zlob / php-json-server

1. Go to this page and download the library: Download zlob/php-json-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zlob / php-json-server example snippets

composer 
 php


namespace App\Http\Controllers;

use Request;
use Response;
use Config;
use JsonServer\JsonServer;

class JsonServerController extends Controller
{
    public function handleRequest($uri)
    {
        $data = Request::all();                                             //request data
        $method = Request::method();                                        //request method
        $jsonServer = new JsonServer();                                     //create new JsonServer instance
        $response = $jsonServer->handleRequest($method, $uri, $data);       //handle request
                                                                            //return Symfony\Component\HttpFoundation\Response
                                                                            //object with content, status and headers
        $response->send();                                                  //send response
    }
}

GET /posts?title=json-server&author=zlob

GET /posts?_start=20&_end=30
GET /posts/1/comments?_start=0&_end=30

GET /posts?_sort=views&_order=desc
GET /posts/1/comments?_sort=votes&_order=asc