Skip to content

CRUD API Instruction

Daniel edited this page Oct 10, 2023 · 7 revisions

Todo App CRUD API

Use 'Java and Spring' or 'NodeJS and NestJS' to build the following CRUD API

  • NodeJS - NestJS Setup: https://docs.nestjs.com/first-steps
  • Spring Setup: https://spring.io/quickstart
  • Everything can just be stored in memory (If the CRUD API is shutdown, tasks will be lost, this is ok)

API Structure

The Todo App CRUD API is a set of endpoints that allow users to perform CRUD (Create, Read, Update, Delete) operations on todo items in the Todo App.

The API includes the following endpoints:

  • GET /todos: Retrieves a list of all todo items.
  • GET /todos/{id}: Retrieves a specific todo item by its ID.
  • POST /todos: Creates a new todo item.
  • PUT /todos/{id}: Updates an existing todo item.
  • DELETE /todos/{id}: Deletes a todo item.

Each endpoint accepts and returns JSON data.

Sample CURL requests with responses for the Todo App CRUD API:

  1. Retrieve a list of all todo items:

    curl -X GET /todos

    Response:

    [
      {
        "id": 1,
        "title": "Buy groceries",
        "completed": false
      },
      {
        "id": 2,
        "title": "Finish report",
        "completed": true
      },
      ...
    ]
  2. Retrieve a specific todo item by its ID:

    curl -X GET /todos/{id}

    Response:

    {
      "id": 1,
      "title": "Buy groceries",
      "completed": false
    }
  3. Create a new todo item:

    curl -X POST /todos \\
      -H "Content-Type: application/json" \\
      -d '{"title": "Walk the dog", "completed": false}'

    Response:

    {
      "id": 3,
      "title": "Walk the dog",
      "completed": false
    }
  4. Update an existing todo item:

    curl -X PUT /todos/{id} \\
      -H "Content-Type: application/json" \\
      -d '{"title": "Buy groceries", "completed": true}'

    Response:

    {
      "id": 1,
      "title": "Buy groceries",
      "completed": true
    }
  5. Delete a todo item:

    curl -X DELETE /todos/{id}

    Response:

    {
      "message": "Todo item deleted successfully"
    }

A Todo Item (DataModel)

The data model consists of the following fields:

  • id (integer): Represents the unique identifier of a todo item.
  • title (string): Represents the title or description of a todo item.
  • completed (boolean): Represents the completion status of a todo item. It is true if the todo item has been completed, and false otherwise.

This data model is used to store information about a specific todo item in the Todo App. It includes an ID for identification, a title for describing the task, and a completion status to indicate whether the task has been completed or not.

Clone this wiki locally