Skip to content

A little repository using slim php, rabbitMQ, MySQL, Nginx and Docker

Notifications You must be signed in to change notification settings

Gabrielpatrola/slim-php

Repository files navigation

PHP Slim 4 Framework


PHP | Slim

Language used Made with Slim

💭 About

This is a repository to test a small application using the Slim 4, rabbitMQ, MySQL, Docker and Nginx

👨‍💻 Stack used

⁉ How to use

🤔 Requirements

To be able to run this project, first you will need to have in your machine:

  • Git to be able to clone this repository
  • Docker to be able to run the application

📝 Step to Step

First the repository in your computer

  1. Cloning the repository
  # Clone the repository
  $ git clone git@github.com:Gabrielpatrola/slim-php.git
  # Go to the project folder
  $ cd slim-php
  1. Create a .env file
  # Create a .env file
  $ cp .env.example .env # Or copy .env.example .env (windows)
  1. Make changes in .env file

Open the .env file and change the values in database variables and/or other variables if necessary.

  1. Starting the application

The application have everything in a docker container with Nginx, Mysql, PHP and Rabbitmq, so you will need to build the container with the command above:

$ docker-compose up -d --build 
  1. Installing the project dependencies
  $ docker exec -it slim_php composer install  
  1. Running the database migrations
  $  docker exec -it slim_php php vendor/bin/doctrine orm:schema-tool:update --force

If everything went good, you will be able to access the application in http://localhost:8080

The app have 4 endpoints:

POST /users

This endpoint is used to create a new user with the payload above:

{
  "name": "Test User",
  "email": "test@test.com",
  "password": "12345678"
}

POST /login

This endpoint is used to create a new user with the payload above:

{
  "email": "test@test.com",
  "password": "12345678"
}

GET /stock

This endpoint expected a query param q that recieves the stock symbol and also a header param called Authorization with a token that can be got using the login route.

This endpoint returns all information for the requested stock using the Stooq API

GET /history

This endpoint shows all stock requests that got succefull results. This endpoint also needs the Authorization header

More information about the endpoints can be found in the postman collection in this link

  1. Sending emails

This application uses rabbitmq to send asynchronous emails, the command to execute the script is:

$ docker exec -it slim_php php consumer.php  
  1. Testing the application
  $ docker exec -it slim_php composer test  

📚 Postman and Useful Links