https://github.com/edsonmsouza/php-api-to-do-list
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
https://github.com/edsonmsouza/php-api-to-do-list
Last synced: over 1 year ago
JSON representation
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
- Host: GitHub
- URL: https://github.com/edsonmsouza/php-api-to-do-list
- Owner: EdsonMSouza
- License: cc-by-sa-4.0
- Created: 2021-10-02T19:22:56.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-11T04:06:46.000Z (about 3 years ago)
- Last Synced: 2025-02-27T17:44:18.081Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 19.5 MB
- Stars: 12
- Watchers: 2
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP API TO-DO-LIST v.2.0


This API aims to present a brief to consume an API resources, mainly for students in the early years of Computer Science courses and the like. For this reason, it has few EndPoints to use, and can be expanded according to the need.
The API have two features: "**USER**" and "**TASK**". The aim is that a user can register their to-do list, performing basic data manipulation on both resources. As a bonus, the API allows, after creating the user, sending an image to the user's profile.
As it is an instructional project, **it is not recommended** that it be applied in a production environment, as safety routines and tests have not been implemented. These resources must be researched and implemented, following the current rules, in addition to good practices. Built in **PHP 7** (see below), it allows the beginner to understand the mechanisms of access to the resources of an API.
```html
PHP 7.4.3 (cli) (built: Jul 5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group Zend Engine v3.4.0,
Copyright (c) Zend Technologies with Zend OPcache v7.4.3,
Copyright (c), by Zend Technologies
```
## How to use this content?
This content has _free license for use_ (CC BY-SA 4.0).
If you want to collaborate in this repository with any improvements you have made. To do this, just make a Fork and send Pull Requests.
## Composer
Changes should be updated via composer dump-autoload -o on your local machine.
## Documentation
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for **users** and **tasks** resources.
## API Structure
```text
+---api
\task\
---delete
---edit
---new
---search
---update
\user\
---new
---login
---update
---updateuserpass
---delete
+---src
\---Database
\---Helpers
\---Task
\---User
\---vendor
\---composer
```
## Database
The development uses the MySQL 5, which can be changed at any time according to the need for use. The database should be
configured in Database\Database.php
### Scripts SQL
```sql
CREATE DATABASE name;
```
```sql
CREATE TABLE users
(
id INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
username VARCHAR(32) NOT NULL,
password VARCHAR(32) NOT NULL,
token VARCHAR(20) NOT NULL,
picture TEXT DEFAULT NULL
);
```
```sql
CREATE TABLE tasks
(
id INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
userId INT(3) NOT NULL,
name VARCHAR(50) NOT NULL,
date date NOT NULL,
realized INT(1) NOT NULL
);
```
Attention: in order to delete corresponding tasks to user you need to do a ```ALTER TABLE``` adding a ```FOREIGN KEY``` and ```ON DELETE CASCADE``` option.
```sql
ALTER TABLE tasks
ADD CONSTRAINT pk_user
FOREIGN KEY (userId)
REFERENCES users(id)
ON DELETE CASCADE;
```
## Token
To use this API, a user must first be created with resource below.
A TOKEN will be returned that should be used in all subsequent requests for both user and task data manipulation.
## Domain
The `domain` variable must be filled with the address where the API will be made available like: (https://**domain**/api/{resource}/{parameter})
# __User__ resources
## **NEW**
* parameter: **user/new**/
* method: **post**
* payload
```json
{
"name": "name",
"email": "email",
"username": "username",
"password": "password"
}
```
* header
```json
{"content-type": "application/json"}
```
* success
```json
{
"message": "User Successfully Added",
"id": "user_id",
"token": "YOUR_TOKEN"
}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected Four)"}
{"message": "Could Not Add User"}
{"message": "Missing data in one or more fields"}
{"message": "User Already Exists"}
```
## **LOGIN**
* parameter: **user/login**/
* method: **post**
* payload
```json
{
"username": "username",
"password": "password"
}
```
* header
```json
{"content-type": "application/json"}
```
* success
```json
{
"id": 1,
"name": "John Doe",
"email": "john.doe@domain.com",
"token": "YOUR_TOKEN",
"picture": "BASE64_STRING"
}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected Two)"}
{"message": "Incorrect username and/or password"}
```
## **UPDATE**
* parameter: **user/update/**
* method: **put**
* payload
```json
{
"name": "name",
"email": "email",
"username": "username",
"password": "password",
"picture": "BASE64_STRING" or ""
}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* success
```json
{"message": "User Successfully Updated"}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected Five)"}
{"message": "Incorrect username and/or password"}
{"message": "Could Not Update User"}
```
## **UPDATE USERNAME/PASSWORD**
* parameter: **user/updateuserpass/**
* method: **put**
* payload
```json
{
"username": "username",
"password": "password",
"new_username": "new_username",
"new_password": "new_password"
}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* success
```json
{"message": "User/password Successfully Updated"}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected Four)"}
{"message": "Incorrect username and/or password"}
{"message": "Could Not Update Username/password"}
```
## **DELETE**
* parameter: **user/delete/**
* method: **delete**
* payload
```json
{
"username": "username",
"password": "password"
}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* success
```json
{"message": "User Successfully Deleted"}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected Two)"}
{"message": "Incorrect username and/or password"}
{"message": "Could Not Delete User"}
```
# __Task__ resources
## **NEW**
* parameter: **task/new**/
* method: **post**
* payload
```json
{"name": "Task name"}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* success
```json
{"message": "Task Successfully Added"}
```
* warnings
```json
{"message": "Invalid Arguments Number (Expected One)"}
{"message": "Could Not Add Task"}
```
## **SEARCH**
* parameter: **task/search**/
* method: **post**
* payload
* Payload is not necessary, as the control is performed by `token`.
* Realized field accept values: `0` (open) or `1` (realized)
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* success
```json
[
{
"id": 1,
"userId": 1,
"name": "task name",
"date": "2021-08-16",
"realized": 0
}
]
```
* Warnings
```json
{"message": "Task(s) not found"}
```
## **UPDATE**
* parameter: **task/update**/
* method: **put**
* payload
```json
{
"id": "value",
"name": "Task name",
"realized": "value"
}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* Success
```json
{"message": "Task Successfully Updated"}
```
* Warnings
```json
{"message": "Task(s) not found"}
{"message": "Method Not Allowed"}
{"message": "Invalid Arguments Number (Expected Three)"}
```
## **EDIT**
* parameter: **task/edit**/
* method: **put**
* payload
```json
{"id": "value"}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* Success
```json
{
"id": 2,
"userId": 1,
"name": "Task name",
"date": "2021-08-16",
"realized": 0
}
```
* Warnings
```json
{"message": "Payload Precondition Failed"}
{"message": "Invalid or Missing Token"}
{"message": "Invalid Arguments Number (Expected One)"}
{"message": "Bad Request (Invalid Syntax)"}
{"message": "Token Refused"}
```
## **DELETE**
* parameter: **task/delete**/
* method: **delete**
* payload
```json
{"id": "id_task"}
```
* header
```json
{
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
```
* Success
```json
{"message": "Task deleted Successfully"}
```
* Warnings
```json
{"message": "Task not exist"}
{"message": "Payload Precondition Failed"}
{"message": "Invalid or Missing Token"}
{"message": "Invalid Arguments Number (Expected One)"}
```
### Other Warnings
```json
{"message": "Bad Request (Invalid Syntax)"}
{"message": "Token Refused"}
{"message": "Invalid or Missing Token"}
{"message": "Method Not Allowed"}
{"message": ""}
{"message": ""}
```
# Try Online
You can try online this API with full features.
* URI: [https://todolist-api.edsonmelo.com.br/api/](https://todolist-api.edsonmelo.com.br/api/)
---
## Flutter APP ToDoList
You can test the API functionalities by accessing [here](https://github.com/Wilian-N-Silva/flutter_to_do_list) the APP developed by [Wilian Silva](https://github.com/Wilian-N-Silva).
### Views

___
## How to cite this content
```
DE SOUZA, Edson Melo (2021, August 16). PHP API TO-DO-LIST v.2.0.
Available in: https://github.com/EdsonMSouza/php-api-to-do-list
```
Or BibTeX for LaTeX:
```latex
@misc{desouza2020phpapi,
author = {DE SOUZA, Edson Melo},
title = {PHP API TO-DO-LIST v.2.0},
url = {https://github.com/EdsonMSouza/php-api-to-do-list},
year = {2021},
month = {August}
}
```
## Acknowledgements
* [Arthur Timoteo](https://github.com/arthur-timoteo)
* [Wilian Silva](https://github.com/Wilian-N-Silva)
## License
[![CC BY-SA 4.0][cc-by-sa-shield]][cc-by-sa]
This work is licensed under a
[Creative Commons Attribution-ShareAlike 4.0 International License][cc-by-sa].
[![CC BY-SA 4.0][cc-by-sa-image]][cc-by-sa]
[cc-by-sa]: http://creativecommons.org/licenses/by-sa/4.0/
[cc-by-sa-image]: https://licensebuttons.net/l/by-sa/4.0/88x31.png
[cc-by-sa-shield]: https://img.shields.io/badge/License-CC%20BY--SA%204.0-lightgrey.svg