A simple RESTful API for managing tasks, built with PHP and MySQL.
This project provides endpoints to create, read, update, and delete tasks. It is designed to run locally using XAMPP.
-
Install XAMPP
- Download and install XAMPP from https://www.apachefriends.org/index.html.
- Start Apache and MySQL from the XAMPP control panel.
-
Clone or Copy the Project
- Place the
tasks-api
folder in/Applications/XAMPP/xamppfiles/htdocs/
(macOS) or thehtdocs
directory on your system.
- Place the
-
Import the Database
- Open phpMyAdmin (
http://localhost/phpmyadmin
). - Create a database (e.g.,
tasks_db
). - Import the provided SQL file in db folder named (schema ans seed.sql) to set up the
tasks
table.
- Open phpMyAdmin (
-
Configure Database Connection
- Open
db.php
in the project folder. - Set your database credentials (DB name, user, password, host) as needed.
- Open
http://localhost/tasks-api/
GET /tasks
GET http://localhost/tasks-api/tasks
GET /tasks/{id}
GET http://localhost/tasks-api/tasks/1
POST /tasks
POST http://localhost/tasks-api/tasks
Content-Type: application/json
{
"title": "Buy groceries",
"description": "Milk, Bread, Eggs"
}
PUT /tasks/{id}
PUT http://localhost/tasks-api/tasks/1
Content-Type: application/json
{
"title": "Go shopping",
"description": "Milk, Bread, Eggs, Butter"
}
DELETE /tasks/{id}
DELETE http://localhost/tasks-api/tasks/1
PATCH /tasks/{id}/toggle
PATCH http://localhost/tasks-api/tasks/1/toggle
This endpoint flips the status of the specified task between pending
and completed
.
- Use Postman or a similar tool to test the API endpoints.
- Set the appropriate HTTP method and headers (e.g.,
Content-Type: application/json
for POST/PUT).