A complete REST API built with PHP using Slim Framework, Eloquent ORM, and JWT authentication.
- Slim Framework 4: Fast and lightweight PHP framework
- Eloquent ORM: Database operations with Laravel's Eloquent
- JWT Authentication: Secure token-based authentication
- Validation: Request validation using Respect/Validation
- Password Hashing: Secure password storage with bcrypt
- Install dependencies:
composer install- Setup database:
- Create a MySQL database named
api_rest - Import the database schema:
mysql -u root -p api_rest < database.sql
- Configure environment:
- Copy
.env.exampleto.env - Update database credentials and JWT secret in
.env
- Start the development server:
composer start
# or
php -S localhost:8000 -t publicGET /public- Public route (no authentication required)
POST /register- User registrationPOST /login- User login
GET /private/profile- Get user profile (requires Authorization header)
curl -X POST http://localhost:8000/register \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}'curl -X POST http://localhost:8000/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'curl -X GET http://localhost:8000/private/profile \
-H "Authorization: Bearer YOUR_JWT_TOKEN"├── public/
│ └── index.php # Application entry point
├── src/
│ ├── Controllers/ # Request handlers
│ ├── Middleware/ # JWT middleware
│ ├── Models/ # Eloquent models
│ └── Services/ # JWT and validation services
├── .env # Environment configuration
└── composer.json # Dependencies