Path parameters

The path can also contain parameters that match specific path segments and capture its value into parameters properties of an application call:

    get("/user/{id}") {      val id = call.parameters["id"]    }

Let's look at the newsSources function:

    /**     * Get list of all news sources     */    fun Route.newsSources() {      get("/news-source") {        val (_, _, result) =          "https://newsapi.org/v1/sources".httpGet().responseString()        call.respondText(result.get(), ContentType.Application.Json)      }    }

The function contains a GET request specified using the get function from Route. Inside the get function, we get call, which is an instance of ApplicationCall to handle requests and responses.

We send a GET request to the News API, fetch all the news sources or ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.