I have a node js app that contains a mongoose databse, is there a way I can link it to my android kotlin app? Is there an alternative for axios in Kotlin so that I make http requests to node and get data to the kotlin app?
Asked
Active
Viewed 713 times
0
-
A bit confusion here, nodejs is javascript framework, mongoose if ORM written in javascript for mongodb, and when you say connect to database it usually means you want connect to database itself, not to nodejs server, which using mongodb database. – Ivan Cherviakov Nov 30 '19 at 15:33
1 Answers
1
You can use standard libraries you would use in Java. For example, with HttpURLConnection you can do:
fun sendGet() {
val url = URL("http://www.google.com/")
with(url.openConnection() as HttpURLConnection) {
requestMethod = "GET" // optional default is GET
println("\nSent 'GET' request to URL : $url; Response Code : $responseCode")
inputStream.bufferedReader().use {
it.lines().forEach { line ->
println(line)
}
}
}
}
Or simpler:
URL("https://google.com").readText()

Akolade Adesanmi
- 1,152
- 11
- 15