This is a demo project written in Kotlin with Ktor. It is a to-do list backend with very basic functionality. It uses
- H2 for database
- Exposed for database access
- Flyway for database schema migrations
- Gson for Json serialization/deserialization
Todo API is RESTful. It consumes and produces Json data. There is no authorization or authentication. Providing a valid userId
as a path parameter is enough, because why not? 🤷🏻
All successful responses will have 200 OK
status unless explicitly mentioned.
All handled errors return an error Json in following format with an HTTP status same as the value of code
field.
{
"code": 400,
"message": "Human readable error message"
}
Creates a new to-do item with given data
title
is required, details
is optional
POST /todo/{userId}
{
"title": "Buy Milk",
"details": "1 carton"
}
A successful response will have 201 Created
status.
201 Created
{
"id": 1,
"userId": 1,
"title": "Buy Milk",
"details": "1 carton",
"time": "2020-01-15T14:44:14Z"
}
Lists all to-do items for given user id
GET /todo/{userId}
Response payload will contain a Json array of all to-do items.
200 OK
[
{
"id": 1,
"userId": 1,
"title": "Buy Milk",
"details": "1 carton",
"time": "2020-01-15T14:44:14Z"
}
]
Gets a to-do item with given id
GET /todo/{userId}/{id}
Response payload will contain a Json object of the to-do item.
200 OK
{
"id": 1,
"userId": 1,
"title": "Buy Milk",
"details": "1 carton",
"time": "2020-01-15T14:44:14Z"
}
Updates a to-do item with given data
All fields are optional.
PUT /todo/{userId}/{id}
{
"title": "Buy Soy Milk",
"details": "2 cartons"
}
Response payload will contain a Json object of the to-do item.
200 OK
{
"id": 1,
"userId": 1,
"title": "Buy Soy Milk",
"details": "2 cartons",
"time": "2020-01-15T16:37:23Z"
}
Deletes given to-do item
DELETE /todo/{userId}/{id}
200 OK
{}