vjaykoogu / rest-api-slim-php

Example of REST API with Slim PHP Framework.

Home Page:http://bit.ly/2DdwKkd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST API IN SLIM PHP

Example of REST API with Slim PHP micro framework.

alt text

This simple RESTful API made in Slim version 3, allows CRUD operations to manage resources like: Users, Tasks and Notes.

Build Status Test Coverage Code Quality Quality Gate Status

You can also read this README IN SPANISH.

INSTALLATION:

1- Clone project and install dependencies:

$ git clone https://github.com/maurobonfietti/rest-api-slim-php.git
$ cd rest-api-slim-php
$ cp .env.example .env
$ composer install

2- Create a new MySQL database. For example: "rest_api_slim_php".

From the command line run:

$ mysql -e 'CREATE DATABASE rest_api_slim_php;'

3- Create the structure and load test data into the database.

The database can be updated manually using the following file: database.sql.

It can also be run from the command line:

$ mysql rest_api_slim_php < database/database.sql

4- Configure the connection data with MySQL.

Edit and complete configuration file: .env. For example:

DB_HOSTNAME = '127.0.0.1'
DB_DATABASE = 'rest_api_slim_php'
DB_USERNAME = 'root'
DB_PASSWORD = ''

5- Configure optional environment variables.

For example:

DISPLAY_ERROR_DETAILS=true
APP_DOMAIN='https://www.yourdomain.com'
USE_REDIS_CACHE=false
REDIS_URL=''
SECRET_KEY='YourSuperSecret-KeY'

LOCAL SERVER:

You can start the PHP internal web server by running:

$ composer start

NOTE:

If everything went well 😎, you can access the project locally by entering: Help, Status and Notes.

The composer start command would be the equivalent to execute:

$ php -S 0.0.0.0:8080 -t public public/index.php

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.
  • respect/validation: The most awesome validation engine ever created for PHP.
  • palanik/corsslim: Cross-origin resource sharing (CORS) middleware for PHP Slim.
  • vlucas/phpdotenv: Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.
  • predis/predis: A PHP extension for Redis.
  • firebase/php-jwt: A simple library to encode and decode JSON Web Tokens (JWT) in PHP.

LIST OF DEVELOPMENT DEPENDENCIES:

TESTS:

Access the root of the project and run all tests PHPUnit with composer test.

PHPUnit 8.1.4 by Sebastian Bergmann and contributors.

.......................................................           55 / 55 (100%)

Time: 171 ms, Memory: 12.00 MB

OK (55 tests, 290 assertions)

DOCUMENTATION:

ENDPOINTS:

You can see the API documentation with the full list of endpoints.

  • Help: GET /

  • Status: GET /status

  • Login User: POST /login

  • Create User: POST /api/v1/users

  • Update User: PUT /api/v1/users/{id}

  • Delete User: DELETE /api/v1/users/{id}

  • Get All Tasks: GET /api/v1/tasks

  • Get One Task: GET /api/v1/tasks/{id}

  • Search Tasks: GET /api/v1/tasks/search/{string}

  • Create Task: POST /api/v1/tasks

  • Update Task: PUT /api/v1/tasks/{id}

  • Delete Task: DELETE /api/v1/tasks/{id}

IMPORT WITH POSTMAN:

All the information of the API, prepared to download and use as postman collection: Import Collection.

Run in Postman

HELP AND DOCS:

For more information on how to use the REST API, see the following documentation available on Postman Documenter.

GIVE IT A TRY:

Check it out to this live demo hosted on Heroku.

About

Example of REST API with Slim PHP Framework.

http://bit.ly/2DdwKkd


Languages

Language:PHP 95.4%Language:Shell 3.4%Language:Makefile 0.6%Language:Dockerfile 0.6%