Skip to content

kule-code/php-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP REST API with Oracle Database

A RESTful API built with PHP connected to Oracle Database with JWT authentication.

Features

  • RESTful Endpoints - Full CRUD operations
  • JWT Authentication - Secure token-based authentication
  • Oracle Database - Enterprise-grade database backend
  • Input Validation - Request validation and sanitization
  • Error Handling - Consistent error responses
  • CORS Support - Cross-origin resource sharing
  • Rate Limiting - API rate limiting protection

Tech Stack

PHP Oracle JWT

Requirements

  • PHP 7.4 or higher
  • Oracle Database 11g or higher
  • PHP OCI8 Extension
  • Composer

Installation

  1. Clone the repository
git clone https://github.com/kule-code/php-rest-api.git
cd php-rest-api
  1. Install dependencies
composer install
  1. Configure environment
cp .env.example .env
# Edit .env with your database credentials
  1. Run database migrations
sqlplus username/password@//localhost:1521/ORCL @database/schema.sql
  1. Start server
php -S localhost:8000 -t public

API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login Login and get JWT token
POST /api/auth/refresh Refresh JWT token

Users

Method Endpoint Description
GET /api/users Get all users
GET /api/users/{id} Get user by ID
POST /api/users Create new user
PUT /api/users/{id} Update user
DELETE /api/users/{id} Delete user

Products

Method Endpoint Description
GET /api/products Get all products
GET /api/products/{id} Get product by ID
POST /api/products Create new product
PUT /api/products/{id} Update product
DELETE /api/products/{id} Delete product

Example Requests

Login

curl -X POST http://localhost:8000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "password123"}'

Get Products (with JWT)

curl -X GET http://localhost:8000/api/products \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Project Structure

php-rest-api/
├── public/
│   └── index.php
├── src/
│   ├── Config/
│   │   └── Database.php
│   ├── Controllers/
│   │   ├── AuthController.php
│   │   ├── UserController.php
│   │   └── ProductController.php
│   ├── Middleware/
│   │   └── AuthMiddleware.php
│   ├── Models/
│   │   ├── User.php
│   │   └── Product.php
│   └── Utils/
│       └── JWT.php
├── database/
│   └── schema.sql
├── .env.example
├── composer.json
└── README.md

Response Format

Success

{
    "status": "success",
    "data": { ... }
}

Error

{
    "status": "error",
    "message": "Error description"
}

License

MIT License

Author

kule-code

About

RESTful API built with PHP connected to Oracle Database with JWT authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages