Search⌘ K
AI Features

Fetching new Entities

Explore fetching new entities in a Ktor-based microservice application using Kotlin. Understand how to set up RESTful routes to retrieve single or multiple cats from a database, handle JSON serialization with Kotlin serialization plugin, and write robust tests to validate your endpoints using the Exposed SQL library. This lesson guides you through practical implementation and testing strategies for database interactions in concurrent microservices.

We'll cover the following...

Following the REST practices, the URL for fetching all cats should be /cats, while for fetching a single cat, it should be /cats/123, where 123 is the ID of the cat we are trying to fetch all the rows from the table for. Then, we map each row to our data class.

Adding new routes to the

...
get("/cats") {
   ...
}
get("/cats/{id}") {
   ...
}

The first route is very similar to the /status ...