Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rhumsaa\VndError

Build Status

Rhumsaa\VndError is a PHP implementation of the vnd.error specification. This implementation currently targets the 1b9174148c revision of the specification.

From the vnd.error specification:

vnd.error is a simple way of expressing an error response in XML or JSON.

Often when returning a response to a client a response type is needed to represent a problem to the user (human or otherwise). A media type representing this error is a convenient way of expressing the error in a standardised format and can be understood by many client applications.

This media type is intended for use with the HTTP status codes 4xx and 5xx, though this does not exclude it from use in any other scenario.

Examples

Use application/vnd.error+json or application/vnd.error+xml media types to communicate errors with HTTP 4xx and 5xx status codes.

<?php
$vndError = new Rhumsaa\VndError\VndError();
$error = $vndError->addError('id-1234', 'Invalid title in POST body');
$error->addLink('help', 'http://example.org/api-docs/title', 'The title field');

// For application/vnd.error+json
header('Content-Type: application/vnd.error+json');
echo $vndError->asJson();

// For application/vnd.error+xml
header('Content-Type: application/vnd.error+xml');
echo $vndError->asXml();

Installation

The preferred method of installation is via Packagist, as this provides the PSR-0 autoloader functionality. The following composer.json will download and install the latest version of the VndError library into your project:

{
    "require": {
        "rhumsaa/vnderror": "*"
    }
}

About

application/vnd.error builder/formatter for PHP 5.3+

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages