2017 © Pedro Peláez
 

library border

Request and Response handler incl. JSON-RPC

image

simplon/border

Request and Response handler incl. JSON-RPC

  • Monday, March 24, 2014
  • by fightbulc
  • Repository
  • 1 Watchers
  • 1 Stars
  • 475 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

     _                 _               _                   _           
 ___(_)_ __ ___  _ __ | | ___  _ __   | |__   ___  _ __ __| | ___ _ __ 
/ __| | '_ ` _ \| '_ \| |/ _ \| '_ \  | '_ \ / _ \| '__/ _` |/ _ \ '__|
\__ \ | | | | | | |_) | | (_) | | | | | |_) | (_) | | | (_| |  __/ |   
|___/_|_| |_| |_| .__/|_|\___/|_| |_| |_.__/ \___/|_|  \__,_|\___|_|   
                |_|                                                    

Simplon/Border

A small library to handle http requests and responses including JSON-RPC., (*1)

Version

0.5.2, (*2)

How to install

Since this library is build with PHP 5.4 syntax you are required to have it installed. Simplon/Border can bei installed by either downloading it from github or via Composer. I encourage you to do the latter. Here is a snippet from a possible composer.json file:, (*3)

{
  "require": {
    "php": ">=5.4",
    "simplon/border": "0.5.2"
  }
}

Request object

The request class is basically an interface wrapper for PHP's $_SERVER variable. I also added some methods which help to identify/handle JSON-RPC requests., (*4)

Examples

Just a couple of calls to show you how we roll. Have a look at the class to see all methods:, (*5)

// print request method
echo Request::getInstance()->getMethod();

// print request uri
echo Request::getInstance()->getUri();

// print query string
echo Request::getInstance()->getQueryString();

// print remote ip
echo Request::getInstance()->getRemoteIp();

How to handle JSON-RPC requests?, (*6)

// is that a json-rpc request?
if(Request::getInstance()->isJsonRpc())
{
  // print request id
  echo Request::getInstance()->getJsonRpcId();

  // print method
  echo Request::getInstance()->getJsonRpcMethod();

  // print params | array
  var_dump(Request::getInstance()->getJsonRpcParams());
}

Response object

In the demand of talking HTTP? The response class does exactly that. You can use it to respond to a http request by sending:, (*7)

  • status codes (e.g. 200, 400, 500 ...)
  • initiating a file download
  • initiating a streaming process (chunking)
  • return to referer
  • json-rpc response
  • json response
  • html response
  • text
  • redirect to another address

Examples

Here are a couple of examples. Have a look at the class to see all:, (*8)

// initiating file download
(new Response())->sendFile('/your/file/path/file.pdf', 'application/pdf');

// talk json-rpc
(new Response())->sendJsonRpc('result', ['name' => 'hansi'], 1);

// talk json
(new Response())->sendJson(['name' => 'hansi']);

// send status code
(new Response())->sendStatusCode(500);

The Versions

24/03 2014

dev-master

9999999-dev https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • ext-json *
  • php >=5.4

 

by Tino Ehrich

request response json-rpc

24/03 2014

0.5.4

0.5.4.0 https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-json *

 

by Tino Ehrich

request response json-rpc

20/01 2014

0.5.3

0.5.3.0 https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-json *

 

by Tino Ehrich

request response json-rpc

12/03 2013

0.5.2

0.5.2.0 https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-json *

 

by Tino Ehrich

request response json-rpc

07/03 2013

0.5.1

0.5.1.0 https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-json *

 

by Tino Ehrich

request response json-rpc

07/03 2013

0.5.0

0.5.0.0 https://github.com/fightbulc/simplon_border

Request and Response handler incl. JSON-RPC

  Sources   Download

MIT

The Requires

  • php >=5.3.3
  • ext-json *

 

by Tino Ehrich

request json-rpc respond