Skip to content

Latest commit

 

History

History
165 lines (113 loc) · 2.6 KB

README.md

File metadata and controls

165 lines (113 loc) · 2.6 KB

Todo with Ktor

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

API

1. General Information

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.

Errors

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"
}

2. Creating a Todo Item

Creates a new to-do item with given data

Example Request

title is required, details is optional

POST /todo/{userId}

{
    "title": "Buy Milk",
    "details": "1 carton"
}

Example Response

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"
}

3. Listing Todo Items

Lists all to-do items for given user id

Example Request

GET /todo/{userId}

Example Response

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"
  }
]

4. Getting a Todo Item

Gets a to-do item with given id

Example Request

GET /todo/{userId}/{id}

Example Response

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"
}

5. Updating a Todo Item

Updates a to-do item with given data

Example Request

All fields are optional.

PUT /todo/{userId}/{id}

{
    "title": "Buy Soy Milk",
    "details": "2 cartons"
}

Example Response

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"
}

6. Deleting a Todo Item

Deletes given to-do item

Example Request

DELETE /todo/{userId}/{id}

Example Response

200 OK

{}