Skip to content
PHP API Responder Library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
Responder.php
example_JSON.php
example_XML.php

README.md

PHP-API-Responder-Library

Convert a PHP arrays into a range of common API response formats.

  • XML
  • JSON
  • Query String
  • YAML
  • Serialized PHP Object

Examples

JSON
include_once 'Responder.php';

$responder = new Responder();

$payload = array(
  'parameters' => array(
    'id' => 1231
  ),
  'data' => array(
    'message' => 'Hello World'
  )
);

header('Content-Type: application/json');
header('HTTP/1.1: ' . 200);
header('Status: ' . 200);

echo $responder->to_json($payload);
OUTPUT
{
    "Response": {
        "parameters": {
            "id": 1231
        },
        "data": {
            "message": "Hello World"
        }
    }
}
XML
include_once 'Responder.php';

$responder = new Responder();

$payload = array(
  'parameters' => array(
    'id' => 1231
  ),
  'data' => array(
    'message' => 'Hello World'
  )
);

header('Content-Type: application/xml');
header('HTTP/1.1: ' . 200);
header('Status: ' . 200);

echo $responder->to_xml($payload);
OUTPUT
<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <parameters>
    <id>1231</id>
  </parameters>
  <data>
    <message>Hello World</message>
  </data>
</Response>
You can’t perform that action at this time.