Todo List Fake API for Testing

Overview:

This API is designed to help developers and students practice CRUD (Create, Read, Update, Delete) operations in a Todo list application. Use this dummy API to simulate adding, updating, viewing, or deleting todo tasks with realistic sample data like title, description, status, priority, due date, and tags.

Base URL:

Base URL: https://shrimo.com/fake-api/todos

Todo Schema:

Each todo item in this API follows this structure:

json

{
  "id": "string",
  "title": "string",
  "description": "string",
  "dueDate": "date",
  "priority": "Low | Medium | High | Critical",
  "status": "Not Started | In Progress | Completed",
  "tags": ["string"]
}

API Endpoints:

1. Create a Todo

API URL:

https://shrimo.com/fake-api/todos

Endpoint:

/todos

Method:

POST

Description:

This endpoint allows you to add a new Todo item to your list. Provide details like title, description, due date, priority, status, and optional tags for task organization.

Request Body:

json

{
  "title": "Learn JavaScript",
  "description": "Complete JavaScript basics",
  "dueDate": "2024-11-15",
  "priority": "High",
  "status": "Not Started",
  "tags": ["JavaScript", "Learning"]
}

Example Response:

json

{
  "message": "Todo added successfully.",
  "data": {
      "id": "672f0eaa814c297b16f90096",
      "title": "Learn JavaScript",
      "description": "Complete JavaScript basics",
      "dueDate": "2024-11-15T00:00:00.000Z",
      "priority": "High",
      "status": "Not Started",
      "tags": ["JavaScript", "Learning"]
  }
}

2. Retrieve All Todos

API URL:

https://shrimo.com/fake-api/todos

Endpoint:

/todos

Method:

GET

Description:

This GET endpoint fetches a list of all Todo items in the database. Each task includes essential details like title, description, priority, status, and tags. You can also filter the tasks by status or priority to refine the list based on your needs.

Example Response:

json

[
  {
    "_id": "672f0dee814c297b16f90093",
    "title": "Learn JavaScript",
    "description": "Complete JavaScript basics",
    "dueDate": "2024-11-15T00:00:00.000Z",
    "priority": "High",
    "status": "Not Started",
    "tags": ["JavaScript", "Learning"],
    "createdAt": "2024-11-09T07:23:26.976Z",
    "updatedAt": "2024-11-09T07:23:26.976Z",
    "__v": 0
  }
]

3. Update a Todo

API URL:

https://shrimo.com/fake-api/todos/:id

Endpoint:

/todos/:id

Method:

PUT

Description:

This PUT endpoint allows you to update an existing Todo itemby its id. You can modify properties such as title, description, priority, status, and tags. This is useful for managing and keeping your tasks up to date.

Request Body:

json

{
  "title": "Learn JavaScript - Updated",
  "description": "Complete JavaScript basics",
  "dueDate": "2024-11-15",
  "priority": "High",
  "status": "In Progress",
  "tags": ["JavaScript", "Learning"]
}

4. Delete a Todo

API URL:

https://shrimo.com/fake-api/todos/:id

Endpoint:

/todos/:id

Method:

DELETE

Description:

This DELETE endpoint allows you to delete a Todo itemby its id. Once deleted, the Todo will no longer be available in your list of tasks. This is useful for removing completed or outdated tasks from your Todo list.

Usage with Fetch and Axios

Learn how to interact with the Todo list API using Fetch and Axios. These examples demonstrate how to create, retrieve, and manage tasks in a Todo list application through simple API calls. Use these methods to manage your task data, whether you're using JavaScript or React.

Create Todo (Fetch)

This example demonstrates how to send a POST request using Fetch.

javascript

const createTodo = async () => {
  const response = await fetch('https://shrimo.com/fake-api/todos', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      title: 'Learn JavaScript',
      description: 'Complete JavaScript basics',
      dueDate: '2024-11-15',
      priority: 'High',
      status: 'Not Started',
      tags: ['JavaScript', 'Learning']
    })
  });
  const data = await response.json();
  console.log(data);
};

createTodo();
Retrieve All Todos (Fetch)

Use the Fetch API to retrieve all Todo items from the list, including their details like title, description, status, and priority.

javascript

const getTodos = async () => {
const response = await fetch('https://shrimo.com/fake-api/todos');
const data = await response.json();
console.log(data);
};

getTodos();
Update Todo (Fetch)

Use the Fetch API to update an existing Todo item by its ID, modifying details like title, description, priority, status, and tags.

javascript

const updateTodo = async (id) => {
const response = await fetch(`https://shrimo.com/fake-api/todos/${id}`, {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    title: 'Learn JavaScript - Updated',
    description: 'Complete JavaScript basics',
    priority: 'High',
    status: 'In Progress'
  })
});
const data = await response.json();
console.log(data);
};

updateTodo('672f0dee814c297b16f90093');
Delete Todo (Fetch)

Use the Fetch API to delete a Todo item by its ID, removing it from the list permanently.

javascript

const deleteTodo = async (id) => {
 const response = await fetch(`https://shrimo.com/fake-api/todos/${id}`, {
   method: 'DELETE'
 });
 const data = await response.json();
 console.log(data);
};

deleteTodo('672f0dee814c297b16f90093');

Create Todo (Axios)

In this example, Axios is used to send a POST request for creating a new Todo item.

javascript

import axios from 'axios';

const createTodo = async () => {
  try {
    const response = await axios.post('https://shrimo.com/fake-api/todos', {
      title: 'Learn JavaScript',
      description: 'Complete JavaScript basics',
      dueDate: '2024-11-15',
      priority: 'High',
      status: 'Not Started',
      tags: ['JavaScript', 'Learning']
    });
    console.log(response.data);
  } catch (error) {
    console.error('Error creating todo:', error);
  }
};

createTodo();
Retrieve All Todos (Axios)

Use Axios to retrieve all Todo items from the list, including their details such as title, description, status, and priority.

javascript

import axios from 'axios';

const getTodos = async () => {
  try {
    const response = await axios.get('https://shrimo.com/fake-api/todos');
    console.log(response.data);
  } catch (error) {
    console.error('Error retrieving todos:', error);
  }
};

getTodos();
Update Todo (Axios)

Use Axios to update an existing Todo item by ID, modifying properties like title, description, priority, status, and tags.

javascript

import axios from 'axios';

const updateTodo = async (id) => {
try {
  const response = await axios.put(`https://shrimo.com/fake-api/todos/${id}`, {
    title: 'Learn JavaScript - Updated',
    description: 'Complete JavaScript basics',
    priority: 'High',
    status: 'In Progress'
  });
  console.log(response.data);
} catch (error) {
console.error('Error updating todo:', error);
}
};

updateTodo('672f0dee814c297b16f90093');
Delete Todo (Axios)

Use Axios to delete a Todo item by ID, removing it from the list permanently.

javascript

import axios from 'axios';

const deleteTodo = async (id) => {
try {
  const response = await axios.delete(`https://shrimo.com/fake-api/todos/${id}`);
  console.log(response.data);
} catch (error) {
  console.error('Error deleting todo:', error);
}
};

deleteTodo('672f0dee814c297b16f90093');