Skip to content

gkallenberg/php-microservice-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages