Skip to content

Instantly share code, notes, and snippets.

@davidcostadev
Last active February 4, 2020 14:25
Show Gist options
  • Save davidcostadev/25f399176ca468ee20131a64ac8798ef to your computer and use it in GitHub Desktop.
Save davidcostadev/25f399176ca468ee20131a64ac8798ef to your computer and use it in GitHub Desktop.

TODO List Project

API spec of to handle with list of tasks

Features

  1. List
  2. Create
  3. Edit
  4. Delete

Endpoints

  • GET /tasks
  • POST /tasks
  • GET /tasks/{id}
  • PUT /tasks/{id}
  • DELETE /tasks/{id}

Default Response Status

code description
200 OK
201 Created
204 Deleted
404 Not found
422 Unprocessable entity
500 Internal server error

Task Entity

field type
id PK - number or uuid
title varchar(255), NOT NULL
description text
is_completed boolean
created_at datetime ISO 8601 UTC
modified_at datetime ISO 8601 UTC

Endpoints descriptions

GET /tasks

Response

status: 200

1. With Data
{
  "data": [
    {
      "id": 1,
      "title": "Some title",
      "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
      "is_completed": true,
      "created_at": "2019-08-09T08:00:00",
      "modified_at": "2019-08-09T08:00:00"
    }
  ],
  "meta": {
    "per_page": 50,
    "page": 1,
    "total_items": 151,
    "total_pages": 4
  }
}
2. With empty data
{
  "data": [],
  "meta": {
    "per_page": 50,
    "page": 1,
    "total_items": 0,
    "total_pages": 0
  }
}

POST /tasks

body:

{
  "title": "Some title",
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "is_completed": true
}

Response

status: 201

{
  "id": 1,
  "title": "Some title",
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "is_completed": true,
  "created_at": "2019-08-09T08:00:00",
  "modified_at": "2019-08-09T08:00:00"
}

Error Response

status: 422

{
  "errors": [{ "key_error": "Invalid title parse" }]
}

GET /tasks/{id}

Response

status: 200

{
  "id": 1,
  "title": "Some title",
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "is_completed": true,
  "created_at": "2019-08-09T08:00:00",
  "modified_at": "2019-08-09T08:00:00"
}

Error Response

1. Not found

status: 404

no content needed

2. Unprocessable Entity

status: 422

{
  "errors": [{ "key_error": "Invalid title parse" }]
}

POST /tasks/{id}

body:

{
  "title": "Some title",
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "is_completed": true
}

Response

status: 200

{
  "id": 1,
  "title": "Some title",
  "description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit.",
  "is_completed": true,
  "created_at": "2019-08-09T08:00:00",
  "modified_at": "2019-08-09T08:00:00"
}

Error Response

status: 422

{
  "errors": [{ "key_error": "Invalid title parse" }]
}

DELETE /tasks/{id}

Response

status: 204

no content needed

Error Response

1. Not found

status: 404

no content needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment