Skip to content

A starter source code for a handy PHP restful API development.

Notifications You must be signed in to change notification settings

zikju/php-api-starter

Repository files navigation

php-api-starter

A starter source code for a handy PHP restful API development.

This project created mainly for myself - to learn and practice PHP OOP.

Requirements

  • PHP: >=7.4
  • MySQL: >=5.7
  • Composer

Packages used

ThingEngineer/PHP-MySQLi-Database-Class
MysqliDb is MySQLi wrapper and object mapper with prepared statements.

steampixel/simplePHPRouter
Simple and small single class PHP router that can handle the whole URL routing.

Respect/Validation
"The most awesome validation engine ever created for PHP!"

firebase/php-jwt
A simple library to encode and decode JSON Web Tokens (JWT) in PHP.

vlucas/phpdotenv
Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.

Features

  • JWT Token Authentication
  • JWT Refresh Tokens
  • Users management
  • Role-based routes protection (user, admin)
  • More to come...

Installation

  • Clone repository:
    git clone https://github.com/zikju/php-api-starter

  • Install composer dependencies:
    composer install

  • Import file database.sql into your MySQL database

  • Edit file .env.example.
    Change MySQL logins variables to match your own database settings:

 DB_HOST = localhost
 DB_PORT = 3306
 DB_DATABASE = database_name
 DB_USERNAME = root
 DB_PASSWORD =
  • Rename file .env.example to .env

  • (optional) For easiest way to test endpoints - import file POSTMAN_ENDPOINTS.json into your Postman workflow.
    After file import - find Collection variables and change API_URL to your project url.

Endpoints

Authentication endpoints:

Method Endpoint Parameters Description
POST /auth/login email string required
password string required
login user
GET /auth/logout logout user
GET /auth/refresh-token refresh token

Users endpoints:

All RESTful API endpoints below requires a Authorization: Bearer xxxx header set on the HTTP request.
xxxx is replaced with token generated from the /auth/login endpoint above.

Method Endpoint Parameters Description
POST /users email string - required
password string - required
role string
status string
notes string
Create new user
GET /users/:id :id integer - required Get user information
DELETE /users/:id :id integer - required Delete user
PUT /users/:id/edit :id integer - required
role string
status string
notes string
Edit user common data
PUT /users/:id/edit/email :id integer - required
email string - required
Change user email

About

A starter source code for a handy PHP restful API development.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published