Giter Site home page Giter Site logo

todo-list-api's Introduction

Todo List API

Details

Todo List PHP Application Programming Interface

PHP 7 script that adds a REST API to a MySQL 5.5 InnoDB database

Related projects:

React todoApp This is a sample todo App written by React js and php

Requirements

  • PHP 7.0 or higher with PDO drivers for MySQL, PgSQL or SqlSrv enabled
  • MySQL 5.6 / MariaDB 10.0 or higher for spatial features in MySQL

Installation

Upload script folder somewhere and enjoy!

For local development you may run PHP's built-in web server:

php -S localhost:8080

Test the script by opening the following URL:

http://localhost:8080/index.php/

Don't forget to modify the configuration at the bottom of the file.

Configuration

Edit the following lines in the bottom of the file "config/Database.php":

    private $host = 'xxx';
    private $db_name = 'xxx';
    private $username = 'xxx';
    private $password = 'xxx';

CRUD + List

The example todo has only a a few fields:

todo
=======
 id
 item
 sort
 todoStatu
 addDate
 completDate

The CRUD + List operations below act on this table.

Create

If you want to create a record the request can be written in URL format as:

POST create/task/

You have to send a body containing:

{
  "item":"Learn PHP"
 }

And it will return the status code 200 And message " Task Created " :

{
 "status":200,
 "message":"Task  Created"
}

Read

To read a record from this table the request can be written in URL format as:

GET /task/1

Where "1" is the value of the primary key of the record that you want to read. It will return:

{

"id": 1,
"item": "Learn PHP",
"sort": "1",
"todoStatu": "1",
"addDate": "2018-09-06 16:07:38",
"completDate": "0000-00-00 00:00:00"
}

Update

To update a record in this table the request can be written in URL format as:

  • Edit task title

PUT /update.php

Send as a body:

{
    "id": 1,
    "item":"PHP"
}

Where "id: 1" is the value of the primary key of the record that you want to update.

This adjusts the title of the task. And it will return the status code 200 And message " Task Updated " :

{
 "status":200,
 "message":"Task Updated"
}
  • Mark as Completed

    Send as a body:

    {
        "id": 1,
        "sort":2,
        "type":2
    }

    Where "id: 1" is the value of the primary key of the record that you want to mark as completed.

This adjusts the status of the task. And it will return the status code 200 And message " Task Completed " :

{
 "status":200,
 "message":"Task Completed"
}
  • Mark as Uncompleted

    Send as a body:

    {
        "id": 1,
        "sort":2,
        "type":1
    }

    Where "id: 1" is the value of the primary key of the record that you want to mark as Uncompleted.

This adjusts the status of the task. And it will return the status code 200 And message " Task uncompleted " :

{
 "status":200,
 "message":"Task Uncompleted"
}

Delete

DELETE /delete.php/

If you want to delete a record from this table the request can be written in URL format as:

{
"id":1,
"type":2,
"sort":2
}

Where "id: 1" is the value of the primary key of the record that you want to delete and type is status of task (completed =2 or uncompleted =1) sort is the task position in list .

Sort

To update a record sort in this table the request can be written in URL format as:

PUT /update.php

Send as a body:

{
    "from": 1,
    "posFrom":2,
    "to":2,
    "posTo":1
}
  • from : the id of the item you want to change
  • posFrom : the sort of item want to change
  • to : The id of the item you want to change to
  • posTo: The sort of the item you want to change to

This adjusts the position of the task. And it will return the status code 200 And message " Tasks Sort Updated " :

{
 "status":200,
 "message":"Tasks Sort Updated"
}

List

To list records from this table the request can be written in URL format as:

GET http://localhost:8080/ or GET http://localhost:8080/index.php/

It will return:

{
"uncompleted": [
   {
      "id": "2",
       "item": "Learn React js",
       "sort": "1",
       "todoStatu": "1",
       "addDate": "2018-09-07 22:29:26",
       "completDate": "0000-00-00 00:00:00"
  }
],
"completed": [
    {
      "id": "2",
      "item": "Learn  PHP",
      "sort": "1",
      "todoStatu": "2",
      "addDate": "2018-07-27 14:25:00",
      "completDate": "2018-09-07 23:20:13"
   }
  ]
}

todo-list-api's People

Contributors

jamalhassouni avatar

Stargazers

 avatar

Watchers

 avatar

todo-list-api's Issues

error when creating task

when i enter url in postman
http://localhost/Todo-List-API/create/task/ ****** what happen ********

Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404
localhost
Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.10

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.