GithubHelp home page GithubHelp logo

sean-olson / api-another-todo-service-in-php Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 57 KB

A simple REST API to support a To-Do web application, written in PHP.

License: MIT License

TSQL 4.96% PLpgSQL 4.57% PHP 90.47%

api-another-todo-service-in-php's Introduction

Yet Another To-Do API (YATA)

A simple REST API to support a To-Do web application -- the Hello World of frontend frameworks. YATA is written in PHP and depends on Apache and MySQL.

Setting Up YATA:

1. Download the Project

Clone or download the GitHub repo to your computer.

2. Load the Code Files into Server Environment

Implementations may differ significantly, but to get up and running quickly just copy the contents of the /src folder into the DocumentRoot of your Apache Server, as configured in your instance (see the httpd.conf file).

3. Setup the Database

The API depends on a MySQL database to function. Setup is a simple three-step process.

  1. Create a database for your To-Do project, named db_todo.

  2. Create the database table and view by running the two scripts in the SQL/ directory of the project folder, running each script in your installed instance of MySQL. Make sure to execute the scripts in order.

    • 1_tbl_todo_items.sql will create a database table, tbl_todo_items where the API stores the to-do items
    • 2_vw_todo_items.sql will create a database view, vw_todo_ietms that provides a filtered view of tbl_todo_items, eliminating deleted to-do items.
  3. Set the DB credentials in the todo.ini file.

    Database connectivity and authentication require setting three properties in the todo.ini file.

    db_name = 'db_todo'
    user_name =  'YOUR_USER_NAME_HERE'
    password = 'YOUR_PASSWORD_HERE'
    

The file is located in the root of the project. For security reasons, it's expected that this file will sit in the same directory as Apache's DocumentRoot folder. If the relative location of the todo.ini changes in relationship to the code files, the relative path statement used to parse the file will need to be updated. (see the getDbConnection() method in src/v1/controllers/db_controller.php)

4. Review the .htaccess File

The rewrite rules in the .htaccess file allow use of standard API route names in your application, rather than the less-pretty FQDN with query-string parameters. The .htaccess file needs to be inside the v1 folder, alongside the directories for controllers and models.

5. The tbl_todo_items Entity

  • todo_item_id bigint(20) NOT NULL,
  • todo_item_name varchar(255) NOT NULL,
  • todo_item_description text DEFAULT NULL,
  • todo_item_due_date datetime DEFAULT NULL,
  • todo_item_is_completed enum('Y','N') NOT NULL,
  • is_deleted tinyint(1) DEFAULT 1

Using YATA:

YATA includes a set of routes that support full CRUD operations against the tbl_todo_items entity, providing a platform for a functional To-Do application.

The To-Do Item Schema
{
    "id":{"type":"integer"},
    "name":{"type":"string", "required":true, "maximum":255},
    "description":{"type":"string"," required":false},
    "due_date":{"type":"string", "format":"date-time", "required":false},
    "is_completed": {"type":string", "enum":["Y", "N"], required":true} 
}
GET Methods
  • /v1/todo : returns an array of all to-do items.
  • /v1/todo/:id : returns the to-do item for the given id (if it exists).
  • /v1/todo/complete : returns an array of all the completed to-do items.
  • /v1/todo/incomplete : returns an array of all the uncompleted to-do items.
  • /v1/todo/page/:number : returns a page of to-do items to the client (if it exists). Page size is fixed at 20 items.
POST Method
  • /v1/todo : requires a to-do item in JSON format, name and is_completed properties are required.
PUT Method
  • /v1/todo/:id : requires a to-do item in JSON format with updated fields only.
DELETE Method
  • /v1/todo/:id

api-another-todo-service-in-php's People

Contributors

sean-olson avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.