Skip to content

About

Implementation of JSend standard JSON response

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

jsend-response

Implementation of the JSend standard JSON response.

Usage

// Success
$jsend = new JSend();
$jsend->success();

// Fail
$jsend = new JSend();
$jsend->fail("Invalid username");

// Error with optional code
$jsend = new JSend();
$jsend->error("Unable to communicate with database")->addCode(10);

// Transform Exception
$jsend = new JSend();
try {
    doWork();
} catch (SomeExeption $exception) {
    $result = $jsend->errorException($exception)->getJson();
}

// Example of use in Slim framework 
$app = new \Slim\App();

$container = $app->getContainer();

$container['jsend'] = function() {
    return new \JSend\JSend();
};

$app->get('/jsend',  function (Request $request, Response $response, array $args) {
    $result = $this->get('jsend')->success();
    return $response->withJson((string) $result);
});

Also check the unit test.

Development

Run unit tests:

$ composer run-tests

Run phpcs, phpmd and phpcpd:

$ composer coding-standard

About

Implementation of JSend standard JSON response

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages