Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/devatreides/php-api-rest

A simple API REST application with PHP
https://github.com/devatreides/php-api-rest

Last synced: 29 days ago
JSON representation

A simple API REST application with PHP

Awesome Lists containing this project

README

        


PHP-Video-Maker

------

## Prerequisites

- PHP 8.1
- PostgreSQL

## Installation

- Clone the repository
- Install de dependencies running `composer install`
- Run the migrations with `./vendor/bin/doctrine-migrations migrate --configuration ./src/Config/migrations.php --db-configuration ./src/Config/database.php`
- Up the server with `php -S localhost:8000 -t public/index.php`

### docker

If you want to use docker, you can make use of the `build` script in the root of the project. It will run simplier commands to up the server:

- `./build composer install` to install the dependencies
- `./build migrations migrate` to run the migrations (Change host value in `./src/Config/database.php` to `host.docker.internal`)
- `./build serve` to up the server

p.s. The `build` script will only run the application in container. To run the migrations, you need to have the database up and running.

## Usage

The API has several endpoints to manage users. The user has to types: *admin* and *user*. The *admin* can do everything that the *user* can do and more. The endpoints and their details are listed below:

- `POST /login` to authenticate the user
- who can use: *admin* and *user*
- headers: `Content-Type: application/json`
- payload: `{email: string, password: string, code: string (if MFA is enabled)}`
- returns: `{token: string}`

- `POST /register` to register a new user
- who can use: *admin* and *user*
- headers: `Content-Type: application/json`
- payload: `{name: string, email: string, password: string}`
- returns: `{message: string}`

- `GET /enable-mfa` to enable the MFA authentication
- who can use: *admin* and *user*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{}`
- returns: `{secret: string, qrCode: string}`

- `POST /verify-mfa` to verify the MFA authentication
- who can use: *admin* and *user*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{code: string}`
- returns: `{message: string}`

- `POST /users` to create a new user
- who can use: *admin*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{name: string, email: string, password: string, isAdmin: boolean}`
- returns: `{user: object}`

- `PUT /users/{id}` to update a user name
- who can use: *admin* and *user*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{name: string}`
- returns: `{user: object}`

- `POST /users/{id}/deactivate` to deactivate a user
- who can use: *admin*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{}`
- returns: `{message: string}`

- `POST /users/{id}/activate` to activate a user
- who can use: *admin*
- headers: `Content-Type: application/json|Authorization: `
- payload: `{}`
- returns: `{message: string}`