This repository contains a basic implementation of a RESTful API in PHP with MySQL database connectivity. The API provides endpoints for performing CRUD (Create, Read, Update, Delete) operations on user data. It utilizes PHP's built-in mysqli
extension for interacting with the MySQL database.
-
Enables cross-origin requests using CORS headers
-
Supports CRUD operations on user data
-
Handles JSON data for request and response payloads
-
Provides error handling and appropriate HTTP response codes
-
Includes a database dump file (
test.sql
) with sample data
-
PHP 7 or later
-
MySQL database
-
Clone the repository:
git clone https://github.com/halloweeks/php-rest-api.git
-
Import the
test.sql
file into your MySQL database. -
Configure the database connection settings:
-
Open
database.php
. -
Modify the following lines with your MySQL database credentials:
$mysqli = new mysqli('127.0.0.1', 'root', '1234');
-
-
Upload the code to your PHP server.
-
Test the API endpoints using your preferred HTTP client (e.g., cURL, Postman).
The following endpoints are available:
-
POST /api/v1/account/info
: Retrieve user information by user ID.Example request body:
{ "user_id": 1 }
Example response:
{ "user_id": 1, "username": "user 1", "email": "user1@gmail.com" }
Contributions are welcome! If you find any issues or want to enhance the functionality, feel free to open a pull request.
This project is licensed under the MIT License.