A comprehensive REST API backend built with CodeIgniter 3, featuring JWT authentication, user management, poster/banner management, and category system.
- ✅ JWT Authentication System
- ✅ User Registration & Login
- ✅ User Profile Management
- ✅ Subscription Handling (Basic/Pro/Premium)
- ✅ Category Management
- ✅ Poster/Banner Management
- ✅ Trending Posters Endpoint
- ✅ API Key Authentication
- ✅ CORS Support
- ✅ Clean URL Support
- ✅ MySQL Database
- PHP 7.0 or higher
- MySQL 5.6 or higher
- Apache/Nginx with mod_rewrite enabled
- CodeIgniter 3.x system files
-
Download CodeIgniter 3 System Files
# Download CodeIgniter 3.1.13 (latest version) wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.13.zip unzip 3.1.13.zip cp -r CodeIgniter-3.1.13/system ./
-
Database Setup
- Create a MySQL database named
codeigniter_api
- Import the
database.sql
file - Update database credentials in
application/config/database.php
- Create a MySQL database named
-
Configuration
- Update
base_url
inapplication/config/config.php
- Set your JWT secret key in
application/config/config.php
- Set your API key in
application/config/config.php
- Update
-
Web Server Configuration
- Ensure mod_rewrite is enabled for Apache
- Make sure the
.htaccess
file is working properly
POST /api/auth/login
- User loginPOST /api/auth/register
- User registrationGET /api/auth/profile
- Get user profile (JWT required)PUT /api/auth/update-profile
- Update profile (JWT required)PUT /api/auth/change-password
- Change password (JWT required)
GET /api/categories
- Get all categoriesGET /api/categories/{id}
- Get single categoryPOST /api/categories/create
- Create category (JWT required)PUT /api/categories/update/{id}
- Update category (JWT required)DELETE /api/categories/delete/{id}
- Delete category (JWT required)
GET /api/posters
- Get all posters (with pagination)GET /api/posters/{id}
- Get single posterPOST /api/posters/create
- Create poster (JWT required)PUT /api/posters/update/{id}
- Update poster (JWT required)DELETE /api/posters/delete/{id}
- Delete poster (JWT required)GET /api/posters/trending
- Get trending postersGET /api/posters/category/{id}
- Get posters by category
All requests must include an API key in the header:
X-API-KEY: your-api-key-12345
Protected endpoints require a JWT token:
Authorization: Bearer <jwt-token>
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-H "X-API-KEY: your-api-key-12345" \
-d '{
"email": "admin@example.com",
"password": "password"
}'
curl -X GET "http://localhost:8080/api/posters?page=1&limit=10" \
-H "X-API-KEY: your-api-key-12345"
curl -X POST http://localhost:8080/api/posters/create \
-H "Content-Type: application/json" \
-H "X-API-KEY: your-api-key-12345" \
-H "Authorization: Bearer <jwt-token>" \
-d '{
"title": "My New Poster",
"description": "A beautiful poster design",
"image_url": "https://example.com/image.jpg",
"category_id": 1,
"tags": "design,poster,beautiful"
}'
All API responses follow this format:
{
"success": true,
"message": "Operation successful",
"data": {...}
}
{
"success": false,
"message": "Error description"
}
- user_id (Primary Key)
- username (Unique)
- email (Unique)
- password (Hashed)
- full_name
- phone
- address
- subscription_type (basic/pro/premium)
- is_active
- last_login
- created_at
- updated_at
- category_id (Primary Key)
- name (Unique)
- description
- icon
- color
- is_active
- created_at
- updated_at
- poster_id (Primary Key)
- title
- description
- image_url
- thumbnail_url
- category_id (Foreign Key)
- tags
- is_premium
- is_featured
- download_count
- view_count
- created_at
- updated_at
- Password hashing using PHP's
password_hash()
- JWT token-based authentication
- API key validation
- CORS headers for cross-origin requests
- SQL injection prevention through CodeIgniter's Query Builder
- Input validation and sanitization
- Email: admin@example.com
- Password: password
- Email: john@example.com, Password: password (Pro subscription)
- Email: jane@example.com, Password: password (Basic subscription)
application/config/config.php
- Main configurationapplication/config/database.php
- Database settingsapplication/config/routes.php
- API routes.htaccess
- URL rewriting and CORS headers
The API includes comprehensive error handling with appropriate HTTP status codes:
- 200: Success
- 400: Bad Request
- 401: Unauthorized
- 404: Not Found
- 405: Method Not Allowed
- 500: Internal Server Error
- Ensure the CodeIgniter 3
system
folder is properly installed - Update configuration files with your specific settings
- Test all endpoints after setup
- The API supports CORS for frontend integration
- All responses are in JSON format
- Pagination is supported for poster listings