Last active
August 11, 2022 04:08
-
-
Save up1/64508ca4003af86f9b5afad7bc4a8049 to your computer and use it in GitHub Desktop.
Kotlin REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!" | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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