Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 2 KB

README.md

File metadata and controls

62 lines (43 loc) · 2 KB

NYPL PHP Microservice Starter

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);
});