A simple RESTful API for managing todos, built with Go and featuring in-memory storage.
- List all todos
- Get a single todo
- Create a new todo
- Update an existing todo
- Delete a todo
go run main.goThe API will start on http://localhost:8080 by default.
{
"id": "string",
"title": "string",
"completed": boolean
}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 /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
}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
}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 /todos/:id
Parameters
id: ID of the todo to delete
Response
- Status: 204 - No Content
- Status: 404 - Todo not found
The API returns appropriate HTTP status codes and error messages:
{
"error": "Error message description"
}- Go (Golang)
- Standard library HTTP package for handling requests
- In-memory storage (no database required)