Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 11, 2022 04:08
Show Gist options
  • Select an option

  • Save up1/64508ca4003af86f9b5afad7bc4a8049 to your computer and use it in GitHub Desktop.

Select an option

Save up1/64508ca4003af86f9b5afad7bc4a8049 to your computer and use it in GitHub Desktop.
Kotlin REST API
import javax.servlet.annotation.WebServlet
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
@WebServlet(name = "Hello", value = "/hello")
class HelloController: HttpServlet() {
override fun doGet(req: HttpServletRequest, res: HttpServletResponse) {
res.writer.write("Hello, World!")
}
}
package demo.dw.helloworld.resources
import javax.ws.rs.GET
import javax.ws.rs.Path
@Path("/hello")
class HelloResource(template: String?, defaultName: String) {
@GET
fun hello(): String {
return "Hello World with Drop Wizard"
}
}
package demo
import spark.Request
import spark.Response
import spark.Spark.*
fun main(arguments: Array<String>) {
get("/hello", {
request:Request, respons: Response ->
"Hello World with Spark Java!"
})
}
package demo.spring
//HelloController.kt
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class HelloController{
@RequestMapping("/hello")
fun hello(): String {
return "Hello World with Sprint Boot"
}
}
//Application.kt
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
open class Application {
companion object {
@JvmStatic fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
}
}
package demo
import org.wasabi.app.AppServer
fun main(args:Array<String>) {
var server = AppServer()
server.get("/", {
response.send("Hello wasabi")
})
server.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment