This repository contains a simple PHP REST API implementation using Rest.php
, along with a sample api.php
file that demonstrates basic CRUD operations. The API allows users to perform login functionality as an example, with extensibility for additional endpoints.
- RESTful Handling: Utilizes
Rest.php
for managing HTTP methods (GET, POST, PUT, DELETE). - Database Connectivity: Connects to a MySQL database for storing and retrieving data (adjust credentials in
api.php
). - Login Example: Includes a sample login endpoint (
api.php
) demonstrating POST method handling and basic authentication. - JSON Responses: Outputs responses in JSON format for interoperability.
To run this project, ensure you have the following installed:
- PHP (version 7.3 or higher)
- MySQL server (for database operations)
Rest.php
(included in this repository)
-
Clone the repository:
git clone https://github.com/sandeepsingh91/rest-api-php.git
-
Navigate into the project directory:
cd rest-api-php
-
Update database credentials in api.php:
const DB_SERVER = "127.0.0.1"; const DB_USER = "your_db_username"; const DB_PASSWORD = "your_db_password"; const DB = "your_database_name";
-
Start your local PHP server:
php -S localhost:8000
-
Access the API endpoints defined in
api.php
using a REST client or curl commands. -
Example usage:
-
POST /login: Authenticate a user by sending a POST request with
username
andpassword
parameters.curl -X POST -d "username=admin&password=admin123" http://localhost:8000/api.php/login
-
Replace
localhost:8000
with your server address and port.
-
- POST /login: Authenticate a user with username and password.
- Request:
POST /api.php/login
- Parameters:
username
,password
- Example:
Replace
curl -X POST -d "username=admin&password=admin123" http://localhost:8000/api.php/login
localhost:8000
with your server address and port.
- Request:
Contributions are welcome! If you find any issues or have suggestions for improvements, please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a new Pull Request
Please ensure your code follows the project's coding standards and is well-documented.
This project is licensed under the MIT License.