simplon/border

Request and Response handler incl. JSON-RPC

Maintainers

👁 fightbulc

Package info

github.com/fightbulc/simplon_border

pkg:composer/simplon/border

Statistics

Installs: 496

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

0.5.4 2014-03-24 11:13 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 15d5e9cb46317e42aa991f1ec96229962be85579

  • Tino Ehrich <opensource.woop@efides.com>

responserequestjson-rpc

This package is auto-updated.

Last update: 2026-06-21 03:58:56 UTC


README

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

Simplon/Border

A small library to handle http requests and responses including JSON-RPC.

Version

0.5.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:

{
 "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.

Examples

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

// 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?

// 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:

  • 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:

// 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);