Creating new Entities
Explore how to create new entities in a Ktor microservice by implementing POST endpoints in Kotlin. Learn to handle request parameters, insert data into the database using transactions, and ensure test consistency by cleaning the database before each test. This lesson guides you through writing and passing tests for adding new items in a RESTful service.
We'll cover the following...
We'll cover the following...
Adding a cat to our virtual shelter
Now our task is to add the first cat to our virtual shelter.
Following the REST principles, it should be a POST request, where the body of the request looks something like this:
{"name": "Meatloaf", "age": 4}
We’ll start by writing a new test in our AppTest.kt file:
@Test
fun `POST creates a new cat`() {
...