December 2017
Intermediate to advanced
260 pages
7h 34m
English
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 ...
Read now
Unlock full access