connell/gratis

A framework for REST development in PHP.

v1.0.1 2024-01-13 18:27 UTC

This package is auto-updated.

Last update: 2024-09-13 19:45:48 UTC


README

A lightweight framework for developing REST-like APIs in PHP.


Table Of Contents


Overview

Gratis is a versatile framework designed to promote the separation of concerns, fostering scalable code practices by encapsulating logic within handlers. Primarily tailored for creating robust and scalable APIs that follow the CRUD lifecycle, the framework follows a REST-like architectural style. It allows form seamless interactions with SQL databases, providing a structured and efficient foundation for building web applications.


Composer

The Gratis framework can be used in a composer PHP project by running the following command,

composer require connell/gratis

Intended Structure

│
└── src/
    ├── Models/
    │ └── ...
    │
    ├── Controllers/
    │ └── ...
    │
    ├── Middlewares/
    │ └── ...
    │
    ├── View/
    │ └── ...
    │
    └── ...

The code structure is meticulously crafted to adhere to a well-defined separation of concerns, delineating distinct roles for model, controller, middleware, and view components.

  • Middlewares

    Positioned at the forefront of the process, middlewares gain initial access to client request and response objects before the controller takes charge. This makes them adept at tasks like client verification and handling cross-origin resource sharing.

  • Controllers

    Tasked with managing HTTP requests, controllers within the API play a pivotal role in orchestrating communication with the backend logic, ensuring a seamless exchange of information with the front end.

  • Models

    Endowed with the capability to execute database I/O operations, models uphold a rigorously typed database schema. This commitment ensures robust data integrity and reliability throughout the system.

  • View

    Housed within a dedicated directory, the View encapsulates static webpage code tailored for a single-page web application.

This framework is specifically designed to integrate with static files generated by contemporary front-end frameworks, such as Vue.js or React.


Development

Below details information about the development environment.


Requirements

The required dependencies for this framework are as follows from composer.json,

"require": {
  "php": "^8.3",
  "ext-pdo": "*"
},
"require-dev": {
  "phpunit/phpunit": "^10.5",
  "guzzlehttp/guzzle": "^7.8"
}

Installing Dependencies

The only dependency used in this framework is PHPUnit for development testing. In order to install PHPUnit as well as generate autoload files, run the following command,

composer install

Running The PHPUnit Test Suite

If you want to run the integration tests, the local PHP development server must be running on http://localhost:8000. There is a script to do this in composer.json,

composer dev

In order to the run the entire automated test suite for this framework, execute,

composer test

For just integration,

composer test:integration

For just unit tests,

composer test:unit

or see the GitHub Actions tab.


License

This software is distributed under the MIT license. See LICENSE for more information.





Developed and tested by Connell Reffo in 2024.