PHP API TO-DO-LIST v.2.0
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like. For this reason, it has few EndPoints (resources) to use, and can be expanded according to the need.
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.
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 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.
TODO
Fixedtoken auth
in update modeFixed system login- Update
username
andpassword
- Create
log auth
method
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
+---api
\task\
---delete
---edit
---new
---search
---update
\user\
---new
---search
---update
+---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
CREATE DATABASE <name>;
CREATE TABLE users (
id INT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
username VARCHAR(20) NOT NULL,
password VARCHAR(20) NOT NULL,
token VARCHAR(20) NOT NULL
);
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
);
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.
Resources (User)
Resource | URI | Method |
---|---|---|
NEW | /api/user/new/ | POST |
url = 'http://URI/api/user/new/';
payload = {
"name": "name",
"email": "email",
"username": "username",
"password": "password"
}
header = {
"content-type": "application/json"
}
Success (User created)
{
"message": "User Successfully Added",
"userid": "user_id",
"token": "TOKEN value"
}
Warnings
{
"message": "Invalid Arguments Number (Expected Four)"
}
{
"message": "Could Not Add User"
}
{
"message": "User Already Exists"
}
Resource | URI | Method |
---|---|---|
LOGIN | /api/user/login/ | POST |
url = 'http://URI/api/user/login/';
payload = {
"username": "username",
"password": "password"
}
header = {
"content-type": "application/json"
}
Success
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"token": "YOUR_TOKEN"
}
Warnings
{
"message": "Invalid Arguments Number (Expected Two)"
}
{
"message": "Incorrect username and/or password"
}
Resource | URI | Method |
---|---|---|
UPDATE | /api/user/update/ | PUT |
Attention: username
and password
can not be changed in this version.
url = 'http://URI/api/user/update/';
payload = {
"name": "name",
"email": "email",
"username": "username",
"password": "password"
}
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success
{
"message": "User Successfully Updated'
}
Warnings
{
"message": "Invalid Arguments Number (Expected Four)"
}
{
"message": "Incorrect username and/or password"
}
{
"message": "Could Not Update User"
}
Resources (Task)
Resource | URI | Method |
---|---|---|
NEW | /api/task/new/ | POST |
url = 'http://URI/api/task/new/';
payload = {
"user_id": "user_id",
"name": "Task name"
}
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success (Task created)
{
"message": "Taks Successfully Added"
}
Warnings
{
"message": "Invalid Arguments Number (Expected Two)"
}
{
"message": "Could Not Add Task"
}
Resource | URI | Method |
---|---|---|
SEARCH | /api/task/search/ | POST |
Payload is not necessary, as the control is performed by token.
Realized field accept values: "0" (open) and "1" (realized)
url = 'http://URI/api/task/search/';
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success
[
{
"id": 1,
"userId": 1,
"name": "task name",
"date": "2021-08-16",
"realized": 0
}
]
Resource | URI | Method |
---|---|---|
UPDATE | /api/task/update/ | PUT |
url = 'http://URI/api/task/update/';
payload = {
"id": "value",
"name": "Task name",
"realized": "value"
}
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success
{
"message": "Task Successfully Updated"
}
Warnings
{
"message": "Task(s) not found"
}
{
"message": "Method Not Allowed"
}
{
"message": "Invalid Arguments Number (Expected Three)"
}
Resource | URI | Method |
---|---|---|
EDIT | /api/task/edit/ | POST |
url = 'http://URI/api/task/edit/';
payload = {
"id": "value"
}
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success
[
{
"id": 2,
"userId": 1,
"name": "Task name",
"date": "2021-08-16",
"realized": 0
}
]
Resource | URI | Method |
---|---|---|
DELETE | /api/task/delete/ | DELETE |
url = 'http://URI/api/task/delete/';
payload = {
"id": "id_task"
}
header = {
"content-type": "application/json",
"Authorization": "YOUR_TOKEN"
}
Success
{
"message": "Task deleted Successfuly"
}
{
"message": "Task not exist"
}
Other Warnings
{
"message": "Bad Request (Invalid Syntax)"
}
{
"message": "Token Refused"
}
{
"message": "Invalid or Missing Token"
}
{
"message": "Payload Precondition Failed"
}
{
"message": "Method Not Allowed"
}
{
"message": "
"
}
{
"message": "
"
}
Try Online
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:
@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}
}
License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.