nypl/microservice-starter

There is no license information available for the latest version (1.2.29) of this package.

NYPL Microservice Starter

1.2.29 2018-08-31 14:53 UTC

README

This package is intended to be used as the starter package for PHP-based NYPL Microservices.

This package adheres to PSR-1, PSR-2, and PSR-4 (using the Composer autoloader).

Installation

Via Composer

"require": {
    "nypl/microservice-starter": "~0.1"
}

Requirements

  • PHP >=5.5.0
  • PHP Extensions

Features

  • RESTful HTTP framework (Slim)
  • Database PDO library (Slim-PDO)
  • Kafka message publishing (Rdkafka)
  • Avro serializer (Avro)
  • Swagger documentation generator (swagger-php)
  • Error logging (Monolog)
  • Identity/JWT authentication via NYPL API Gateway (X-NYPL-Identity)

Usage

HTTP/API Server

See the samples/service directory to learn how to create an example service.

Basic Example

Create an index.php with a Service object and your Slim routes:

$service = new NYPL\Starter\Service();

$service->get("/v0.1/bibs", function (Request $request, Response $response) {
    $controller = new Controller\BibController($request, $response);
    return $controller->getBibs();
});

Configure your web server to load index.php on all requests. See the samples/service-config directory for sample configuration files for an Apache .htaccess or Nginx nginx.conf installation.

Swagger Documentation Generator

Create a Swagger route to generate Swagger specification documentation:

$service->get("/swagger", function (Request $request, Response $response) {
    return SwaggerGenerator::generate(__DIR__ . "/src", $response);
});