petstore icon indicating copy to clipboard operation
petstore copied to clipboard

A simple skeleton to build api's based on the chubbyphp-framework, mezzio (former zend-expressive) or slim.

petstore

CI Coverage Status Mutation testing badge

Description

A simple skeleton to build api's based on the chubbyphp-framework.

Requirements

Environment

Add the following environment variable to your system, for example within ~/.bash_aliases:

export USER_ID=$(id -u)
export GROUP_ID=$(id -g)

Docker

docker-compose up -d
docker-compose exec php bash

Urls

  • GET https://localhost/ping
  • GET https://localhost/swagger (https://localhost/openapi)

Pet

  • GET https://localhost/api/pets?sort[name]=asc
  • POST https://localhost/api/pets
  • GET https://localhost/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d
  • PUT https://localhost/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d
  • DELETE https://localhost/api/pets/8ba9661b-ba7f-436b-bd25-c0606f911f7d

DBs

  • jdbc:postgresql://localhost:5432/petstore?user=root&password=root

Installation

Through Composer as chubbyphp/petstore.

composer create-project chubbyphp/petstore myproject "dev-chubbyphp"

Setup

composer setup:dev

Structure

Collection

Collections are sortable, filterable paginated lists of models.

  • App\Collection

Dto

A DTO, or Data Transfer Object, is a simple object used to transport data between software application components.

  • App\Dto

Middleware

Middleware functions can execute code, make changes to the request and response objects. Middleware can generally be added globally or on a per-route basis.

  • App\Middleware

Model

Models, entities, documents what ever fits your purpose the best.

  • App\Model

ORM

ORM Mapping definitions.

  • App\ORM

Parsing

Parses and validates data against predefined schemas, ensuring that incoming data conforms to expected structures and criteria.

  • App\Parsing

Repository

Repositories get data from storages like databases, elasticsearch, redis or whereever your models are stored or cached.

  • App\Repository

RequestHandler

RequestHandler alias Controller, or Controller actions to be more precise. There is a directory with generic crud controllers. If you like the idea adapt them for your generic use case, if not drop them. I highly recommend to not extend them.

  • App\RequestHandler

ServiceFactory

Service factories are the glue code of the dependeny injection container.

  • App\ServiceFactory

Copyright

2024 Dominik Zogg