@@ -19,13 +19,13 @@ fun Application.configureHTTP() {
1919
2020 // Get-Request with the companion object parameter of Fruit Class
2121 get(Fruit .path) {
22- if (isInvalidKey(call.parameters[" key" ].toString())) return @get
22+ if (isInvalidKey(call.parameters[" key" ].toString())) return @get // Check if the Key is WRONG => Stop Here
2323 call.respond(Fruits .list) // Respond with the Fruit List (because of installed ContentNegotiation Plugin in JSON)
2424 }
2525
2626 // Post-Request with the companion object parameter of Fruit Class
2727 post(Fruit .path) {
28- if (isInvalidKey(call.parameters[" key" ].toString())) return @post
28+ if (isInvalidKey(call.parameters[" key" ].toString())) return @post // Check if the Key is WRONG => Stop Here
2929 val fruit = call.receive<Fruit >() // Receive Content of Request as Fruit
3030 if (! Fruits .list.none { it.name == fruit.name }) error(" Name already in use" ) // If name is already in the List throw IllegalStateException
3131 Fruits .list.add(fruit) // Add Fruit to Fruit List
@@ -34,12 +34,13 @@ fun Application.configureHTTP() {
3434
3535 // Delete-Request with the companion object parameter of Fruit Class
3636 delete(Fruit .path) {
37- if (isInvalidKey(call.parameters[" key" ].toString())) return @delete
37+ if (isInvalidKey(call.parameters[" key" ].toString())) return @delete // Check if the Key is WRONG => Stop Here
3838 val name = call.receive<Fruit >().name // Receive Content of Request as Fruit
3939 Fruits .list.removeIf { it.name == name } // Removes the Element with the name of the Request item
4040 call.respond(HttpStatusCode .OK ) // Respond Status Code for clean Communication
4141 }
4242 }
4343}
4444// Methode to check if Key is valid
45+ // In reality, you should never write the key in the source code, but better save it in a Text File or a Database and read it out.
4546fun isInvalidKey (key : String ) = key != " Usw98ayVeR"
0 commit comments