Simple Kotlin backend using Ktor
It will return sample data with image on API GET request
Go to https://start.ktor.io/ and create a project starter.
Open project in IntelliJ and Run it.
Check the URL in the console logs and click on it or type the URL in the browser.
Call the API:
/randomfox
{
id: "2",
name: "Emma",
description: "Emma likes to eat apples",
imageUrl: "http://0.0.0.0:8080/fox/fox2.jpg"
}
/fox?foxId=3
{
"id": "3",
"name": "Florian",
"description": "Florian is always hungry",
"imageUrl": "http://0.0.0.0:8080/fox/fox3.jpg"
}
/fox?foxId=22
{
error: "Item does not exit"
}
/foxes
[
{
"id": "1",
"name": "Florian",
"description": "Florian is always hungry",
"imageUrl": "http://0.0.0.0:8080/fox/fox3.jpg"
},
...
]
First lets build the project to generate the jar file:
- Under Gradle Task, find the task "fatJar", and run it (double click)
- Run it to make sure it is working properly
cd build/libs/
java -jar com.mrthiago.ktor-backend-0.0.1.jar
It should run just as if you had press Run in the IDE.
Build
docker build -t rest-fox .
Run
docker run --name rest-fox-demo -p 8080:8080 rest-fox
-
Initial Tutorial and sample data by Philipp Lackner
-
Build Ktor Project and create Dockerfile by Caelis
-
Fox Images from Google search
-
fatJar task: To build the project jar, used sample code by Maksim Kostromin