Giter VIP home page Giter VIP logo

rest-api-slim-php's Introduction

REST API IN SLIM PHP

Example of RESTful API with Slim PHP micro framework.

This simple API allows you to manage resources such as: users, tasks and notes.

Software License Build Status Quality Gate Status Code Quality Test Coverage Packagist Version

alt text

You can also read this README IN SPANISH.

Main technologies used: PHP 7, Slim 3, MySQL, Redis, dotenv, PHPUnit and JSON Web Tokens.

Also, I use other aditional tools like: Docker & Docker Compose, Travis CI, Swagger, Code Climate, Scrutinizer, Sonar Cloud, PHPStan, PHP Insights, Heroku and CORS.

More info about this project in my post: How to create a REST API using Slim PHP.

I implemented this API in this project. It's a todo list web app developed in Angular.

โš™๏ธ QUICK INSTALL:

Requirements:

  • Git.
  • Composer.
  • PHP 7.4+ or 8.0+.
  • MySQL/MariaDB.
  • Redis (Optional).
  • or Docker.

With Composer:

You can create a new project running the following commands:

$ composer create-project maurobonfietti/rest-api-slim-php [my-api-name]
$ cd [my-api-name]
$ composer restart-db
$ composer test
$ composer start

How to install

With Git:

In your terminal execute this commands:

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

With Docker:

You can use this project using docker and docker-compose.

Minimal Docker Version:

  • Engine: 18.03+
  • Compose: 1.21+

Commands:

# Start the API (this is my alias for: docker-compose up -d --build).
$ make up

# To create the database and import test data from scratch.
$ make db

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

# Stop and remove containers (it's like: docker-compose down).
$ make down

๐Ÿ”ง TROUBLESHOOTING:

If you get stuck, you can try this guide step by step.

๐ŸŽฆ TUTORIALS:

Mini-series of videos about Slim PHP (Spanish Audio ๐Ÿ”‰ ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ฆ๐Ÿ‡ท).

๐Ÿ“น VIDEO #1

How to install and configure this API.

๐ŸŽฅ VIDEO #2

How to use JWT for Authentication.

๐Ÿ“น VIDEO #3

Using Redis Cache.

๐ŸŽฅ VIDEO #4

Deploy Slim PHP on Heroku.

๐Ÿ“ฆ 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: Flexible and feature-complete Redis client for PHP and HHVM.
  • firebase/php-jwt: A simple library to encode and decode JSON Web Tokens (JWT) in PHP.

LIST OF DEVELOPMENT DEPENDENCIES:

๐Ÿšฅ TESTING:

Run all PHPUnit tests with composer test.

$ composer test
> phpunit
PHPUnit 9.5.8 by Sebastian Bergmann and contributors.

........................................................          56 / 56 (100%)

Time: 00:00.408, Memory: 18.00 MB

OK (56 tests, 343 assertions)

SCREENSHOOTS:

Screen Shot API using Browser


Screen Shot API using Postman


๐Ÿ“š DOCUMENTATION:

ENDPOINTS:

INFO:

  • Help: GET /

  • Status: GET /status

USERS:

  • Login User: POST /login

  • Create User: POST /api/v1/users

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

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

TASKS:

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

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

  • Create Task: POST /api/v1/tasks

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

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

NOTES:

  • Get All Notes: GET /api/v1/notes

  • Get One Note: GET /api/v1/notes/{id}

  • Create Note: POST /api/v1/notes

  • Update Note: PUT /api/v1/notes/{id}

  • Delete Note: DELETE /api/v1/notes/{id}

Also, you can see the API documentation with the full list of endpoints.

HELP AND DOCS:

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

IMPORT WITH POSTMAN:

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

Run in Postman

OPEN API SPEC:

Also, you can view the OpenAPI Specification, using Swagger UI.

๐Ÿš€ DEPLOY:

You can deploy this API with Heroku Free.

Deploy

๐ŸŽฎ GIVE IT A TRY:

Check it out to this LIVE DEMO.

โค๏ธ DO YOU LIKE THE PROJECT?

You can support this project inviting me a coffee โ˜• ๐Ÿ˜‹ or giving a star to this repo โญ ๐Ÿ˜Ž.

Buy Me a Coffee at ko-fi.com

๐Ÿ“„ LICENSE

The MIT License (MIT). Please see License File for more information.

rest-api-slim-php's People

Contributors

maurobonfietti avatar scrutinizer-auto-fixer avatar dinsen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.