PHP REST API with Oracle Database
A RESTful API built with PHP connected to Oracle Database with JWT authentication.
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
PHP 7.4 or higher
Oracle Database 11g or higher
PHP OCI8 Extension
Composer
Clone the repository
git clone https://github.com/kule-code/php-rest-api.git
cd php-rest-api
Install dependencies
Configure environment
cp .env.example .env
# Edit .env with your database credentials
Run database migrations
sqlplus username/password@//localhost:1521/ORCL @database/schema.sql
Start server
php -S localhost:8000 -t public
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
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
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
curl -X POST http://localhost:8000/api/auth/login \
-H " Content-Type: application/json" \
-d ' {"email": "user@example.com", "password": "password123"}'
curl -X GET http://localhost:8000/api/products \
-H " Authorization: Bearer YOUR_JWT_TOKEN"
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
{
"status" : " success" ,
"data" : { ... }
}
{
"status" : " error" ,
"message" : " Error description"
}
MIT License
kule-code