/slim4-api-skeleton

Useful skeleton for RESTful API development with PHP and Slim 4.

Primary LanguagePHPMIT LicenseMIT

SLIM 4 - API SKELETON

Useful skeleton for RESTful API development, using Slim PHP micro framework.

Used technologies: PHP, Slim 4, MySQL, PHPUnit, env var, Docker & Docker Compose.

Software License Build Status Coverage Status Packagist Version

QUICK INSTALL:

Pre Requisite:

  • PHP.
  • Composer.
  • MySQL/MariaDB.

With Composer:

You can create a new project running the following commands:

$ composer create-project maurobonfietti/slim4-api-skeleton [my-api-name]
$ cd [my-api-name]
$ composer test
$ composer start

Configure your connection to MySQL Server:

By default, the API use a MySQL Database.

You should check and edit this configuration in your .env file:

DB_HOST='127.0.0.1'
DB_NAME='yourMySqlDatabase'
DB_USER='yourMySqlUsername'
DB_PASS='yourMySqlPassword'

With Docker:

If you like Docker, you can use this project with docker and docker-compose.

MINIMAL DOCKER VERSION:

  • Engine: 18.03+
  • Compose: 1.21+

DOCKER COMMANDS:

# Create and start containers for the API.
$ docker-compose up -d --build

# Checkout the API.
$ curl http://localhost:8081

# Stop and remove containers.
$ docker-compose down

DEPENDENCIES:

LIST OF REQUIRE DEPENDENCIES:

  • slim/slim: Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
  • slim/psr7: PSR-7 implementation for use with Slim 4.
  • pimple/pimple: A small PHP dependency injection container.
  • vlucas/phpdotenv: Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.

LIST OF DEVELOPMENT DEPENDENCIES:

ENDPOINTS:

BY DEFAULT:

  • Help: GET /

  • Status: GET /status

WOULD YOU LIKE TO SUPPORT THIS PROJECT?

ko-fi

That's it!

Now go build a cool RESTful API ;-)