# HTTP Application Template

The httpsoft/http-app package is an application template for quickly creating simple but high-quality web applications and APIs. «Out of the box», the application template is configured to work with JSON for rapid REST API development.

The core of this application template is the HttpSoft\Basis microframework. By default, the devanych/di-container that implements PSR-11 and the monolog/monolog logger that implements PSR-3 are also used. You can easily change the container and logger to your preferred implementations of the corresponding PSRs.

# Installation

This project template requires PHP version 7.4 or later.

Use Composer and its following command to install:

composer create-project --prefer-dist httpsoft/http-app <app-dir>

To verify the installation, go to <app-dir> and start the PHP built-in web server:

cd <app-dir>
composer run serve

After that, open http://localhost:8080 in your browser.

# Testing and checking

The following commands are run in the application directory:

  • composer run test — runs tests.
  • composer run static — runs static analysis code.
  • composer run cs-check — runs checking coding standards.
  • composer run cs-fix — runs automatic correction of violations of encoding standards.
  • composer run check — runs checking coding standards, static analysis code and tests.

# Directory structure

By default, the application template has the following structure:

bin/                  Executable console scripts.
    chmod-var.php     Recursively changing the "var/" directory mode.
config/               Configuration files.
    config.php        Main configuration.
    container.php     Dependency injection.
    pipeline.php      Middleware pipeline.
    routes.php        HTTP request routes.
public/               Files publically accessible from the Internet.
    index.php         Entry script (front-controller).
src/                  Application source code.
    Http/             HTTP application classes (actions, middelware, etc.).
    Infrastructure/   Helper classes (factories, listeners, etc.).
    Model/            Domain model classes (entities, repositories, etc.).
tests/                A set of tests for the application.
vendor/               Installed Composer packages.
var/                  Temporary files (logs, cache, etc.).

You can change the structure of the application template as you like.

# Application life cycle

Read more about creating and using application instances here and here.

  1. The HTTP request refers to the entry script (front-controller) public/index.php.
  2. The entry script loads the configuration, injects dependencies and creates the application to further process the request.
  3. The application registers the middleware pipeline and request routes using the HttpSoft\Router and HttpSoft\Runner components.
  4. The application runs processing the current request, passing it through the entire queue of previously setup middleware and handlers.
  5. Depending on the result of processing the request, an HTTP response is returned, and using the HttpSoft\Emitter component, the application sends the response headers and outputs the response body to the current output buffer.

# User guide