2017 © Pedro Peláez
 

library mediatype

A PHP implementation of some common media types. Uses Symfony HTTP-foundation

image

antoniog85/mediatype

A PHP implementation of some common media types. Uses Symfony HTTP-foundation

  • Wednesday, March 30, 2016
  • by antoniog85
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Media types

Collection+JSON

http://amundsen.com/media-types/collection/examples/, (*1)

Integration

Silex

$app->after(function (Request $request, Response $response) use ($app) {
    $collectionJson = new \Antoniog85\MediaType\CollectionJson();
    $collectionJson->setVersion(getenv('API_VERSION'));
    $collectionJson->setHref($request->getUri());
    $collectionJson->setError($response);
    $collectionJson->setItems($response);

    return $app->json(
        $collectionJson->render(),
        $response->getStatusCode(),
        [
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
            'Content-Type' => 'application/vnd.collection+json',
        ]
    );
});

Lumen

class AfterMiddleware
{
    public function handle($request, Closure $next): Response
    {
        /** @var Response $response */
        $response = $next($request);
        $response->headers->add([
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
            'Content-Type' => 'application/vnd.collection+json',
        ]);
        $collectionJson = new \Antoniog85\MediaType\CollectionJson();
        $collectionJson->setVersion(getenv('API_VERSION'));
        $collectionJson->setHref($request->getUri());
        $collectionJson->setError($response);
        $collectionJson->setItems($response);
        $response->setContent($collectionJson->render());
        return $response;
    }
}

The Versions

30/03 2016

dev-master

9999999-dev

A PHP implementation of some common media types. Uses Symfony HTTP-foundation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Antonio Giuliana

api rest restful content media type hypermedia