File | Date | Author | Commit |
---|---|---|---|
gradle | 2015-07-24 |
![]() |
[21c267] Klask Init Test |
libs | 2015-07-24 |
![]() |
[5bdd76] Add Library and Route Module |
src | 2015-11-03 |
![]() |
[598bd8] jsocle release 1.0.0 |
JSocle-Release-initialize-0.7.zip | 2015-07-30 |
![]() |
[348038] working on urlfor |
LICENSE | 2015-11-03 |
![]() |
[598bd8] jsocle release 1.0.0 |
README.md | 2015-11-03 |
![]() |
[598bd8] jsocle release 1.0.0 |
build.gradle | 2015-11-03 |
![]() |
[598bd8] jsocle release 1.0.0 |
coverage-error.log | 2015-07-24 |
![]() |
[21c267] Klask Init Test |
gradlew | 2015-06-29 |
![]() |
[98abcb] initialize jsocle |
gradlew.bat | 2015-06-29 |
![]() |
[98abcb] initialize jsocle |
jsocle.iml | 2015-11-03 |
![]() |
[598bd8] jsocle release 1.0.0 |
홈페이지 - http://jsocle.com
빠르고 정확하고 안전한 웹 어플리케이션을 만들기위한 Kotlin 으로 만들어진 마이크로 웹 프레임워크이다.
import com.github.jsocle.JSocle
object app : JSocle() {
init {
route("/") { -> "hello, world" }
}
}
fun main(args: Array<String>) {
app.run()
}
기본
app.route("/") { -> "index" }
PathVariable
app.route("/<id:Int>") { id: Int -> "id = " + id }
ReverseRouter
route 의 url 메소드로 url을 생성할 수 있다.
val index = app.route("/") { -> }
val edit = app.route("/<id:Int>) { id: Int -> }
app.route("/showUrl") { -> index.url() + "," + edit.url(1) }
Nested Route
object postApp: Blueprint() {
val list = route("/") { -> }
}
object app: JSocle() {
init {
register(postApp, "/post")
}
}
RequestContext 내부에서는 request Singletone 으로 요청 관련 내용에 접근 할 수 있다.
import com.github.jsocle.request
request.parameters // query staring and post values
request.parameter("key") // access query string and post value
request.method // http method
request.handler // found request handler
request.handlerCallstack // call stack for found requeset handler
request.pathVariables // pathVariables
Request 배부에서 사용되는 데이터를 위한 g 가 있다. 아래 로그인 예쩨 참조
import com.github.jsocle.request
request.g["user"] = User()
import com.gtihub.jsocle.requset
request.session["userId"] = user.id
test client 를 통해서 요청할 수 있다.
assert(app.client.get("/").data == "hello, world")
test client는 state 를 지원한다. app.client 를 사용할 경우 호출될때마다 생성한다.
val client = app.client
assert(client.get("/").data == "1")
assert(client.get("/").data == "2")
assert(app.client.get("/").data == "1")
Server 실행후 직접 호출 할 수 도 있다.
app.run {
assert(app.server.client.get("/") == "hello, world")
}