Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gimlet2/kottpd
REST framework written in pure Kotlin
https://github.com/gimlet2/kottpd
Last synced: 14 days ago
JSON representation
REST framework written in pure Kotlin
- Host: GitHub
- URL: https://github.com/gimlet2/kottpd
- Owner: gimlet2
- License: mit
- Created: 2016-08-18T13:34:58.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-04-22T08:18:57.000Z (7 months ago)
- Last Synced: 2024-08-02T06:16:32.330Z (4 months ago)
- Language: Kotlin
- Homepage:
- Size: 293 KB
- Stars: 74
- Watchers: 3
- Forks: 16
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-cn - kottpd - REST framework written in pure Kotlin (开源库和框架 / Web 开发)
README
# kottpd
Kottpd - REST framework written in pure Kotlin. It is available from maven central repository. It supports plain HTTP and secured HTTPs.
``` xml
com.github.gimlet2
kottpd
0.2.0
`````` kotlin
val server = Server() // default port is 9000
server.staticFiles("/public") // specify path to static content folder
server.get("/hello", { req, res -> res.send("Hello") }) // use res.send to send data to response explicitly
server.get("/hello_simple", { req, res -> "Hello" }) // or just return some value and that will be sent to response automatically
server.get("/do/.*/smth", { req, res -> res.send("Hello world") }) // also you could bind handlers by regular expressions
server.post("/data", { req, res -> res.send(req.content, Status.Created) }) // send method accepts status
// Filters
server.before("/hello", { req, res -> res.send("before\n") })
server.before({ req, res -> res.send("ALL before\n") })
server.after("/hello", { req, res -> res.send("\nafter\n") })
server.after({ req, res -> res.send("ALL after\n") })
// exceptions handler
server.exception(IllegalStateException::class, { req, res -> "Illegal State" })
server.start(9443, true, "./keystore.jks", "password") // for secured conection
server.start()
```