Skip to content

prajjwal2-3/Go-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Todo API

A simple RESTful API for managing todos, built with Go and featuring in-memory storage.

Features

  • List all todos
  • Get a single todo
  • Create a new todo
  • Update an existing todo
  • Delete a todo

Run Locally

go run main.go

The API will start on http://localhost:8080 by default.

API Documentation

Todo Object Structure

{
  "id": "string",
  "title": "string",
  "completed": boolean
}

Endpoints

List All Todos

GET /todos

Response

  • Status: 200
  • Content: Array of todo objects

Example:

[
  {
    "id": "1",
    "title": "Buy groceries",
    "completed": false
  },
  {
    "id": "2",
    "title": "Learn Go",
    "completed": true
  }
]

Get a Single Todo

GET /todos/:id

Parameters

  • id: ID of the todo to retrieve

Response

  • Status: 200 - Success
  • Status: 404 - Todo not found
  • Content: Todo object

Example:

{
  "id": "1",
  "title": "Buy groceries",
  "completed": false
}

Create a Todo

POST /todos

Request Body

{
  "title": "string",
  "completed": boolean (optional, defaults to false)
}

Response

  • Status: 201 - Created
  • Content: Created todo object with generated ID

Example:

{
  "id": "3",
  "title": "Read a book",
  "completed": false
}

Update a Todo

PUT /todos/:id

Parameters

  • id: ID of the todo to update

Request Body

{
  "title": "string",
  "completed": boolean
}

Response

  • Status: 200 - Success
  • Status: 404 - Todo not found
  • Content: Updated todo object

Example:

{
  "id": "1",
  "title": "Buy groceries",
  "completed": true
}

Delete a Todo

DELETE /todos/:id

Parameters

  • id: ID of the todo to delete

Response

  • Status: 204 - No Content
  • Status: 404 - Todo not found

Error Handling

The API returns appropriate HTTP status codes and error messages:

{
  "error": "Error message description"
}

Technologies

  • Go (Golang)
  • Standard library HTTP package for handling requests
  • In-memory storage (no database required)

About

Simple Todo REST API built in Go. No frameworks, just net/http.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages