restkotlinintellij-ideabackendktor

Call another rest api from my server in Ktor


I want to call another web-api from my backend on a specific request of user.

How can I achieve this in Ktor. Like in spring boot we use Rest Template, but how can I do the same in Ktor.

Reference Article for doing the same in spring boot: (Call another rest api from my server in Spring-Boot)


Solution

  • You can use ktor http client

    val client = HttpClient(CIO)
    val response: HttpResponse = client.get("https://ktor.io/")
    println(response.status)
    client.close()
    

    Making HTTP requests in ktor