Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JVM Bindings🔥 #209

Open
11 of 14 tasks
Ethosa opened this issue Dec 6, 2023 · 0 comments
Open
11 of 14 tasks

JVM Bindings🔥 #209

Ethosa opened this issue Dec 6, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request language bindings

Comments

@Ethosa
Copy link
Contributor

Ethosa commented Dec 6, 2023

Checklist

  • HttpRequest;
  • Server;
  • PathParams, PathParam;
  • Queries, Query;
  • HttpHeaders, HttpHeader;
  • HtmlResponse;
  • JsonResponse;
  • FileResponse;
  • WebSockets;
  • Static directories;
  • Mounting other servers;
  • Request Models;
  • Publishing (Maven/Gradle ?);
  • Documentation;

Minimal Example (Kotlin)

val s = Server()

s.get("/") {
    // Just print path
    println(it.path)
    0
}

s.get("/user{userId:int}") {
    // Get path
    println(it.path)

    // Get any path param that you registered
    println(it.pathParams["userId"].int + 10)

    // Iterate over all queries
    println("Queries:")
    for (i in it.queries) {
        println(i)
    }

    // Iterate over all HttpHeaders
    println("HTTP Headers:")
    for (i in it.headers) {
        println(i)
    }

    // answer to request
    // now it sends just like string
    return@get "Hello, world!"
}

s.get("/base") {
    println(it.path)
    return@get BaseResponse(
        "Oops, bad request",
        401,
        listOf(HttpHeader("Programming-Language", "Kotlin"))
    )
}

s.get("/html") {
    println(it.path)
    return@get HtmlResponse(
        "<h1>Oops! Seems like page that you search is not found</h1>",
        404,
        listOf(HttpHeader("Programming-Language", "Kotlin"))
    )
}

s.get("/json") {
    println(it.path)
    return@get JsonResponse(
        Gson().toJson(listOf(1, 2, 3)),
        404,
        listOf(HttpHeader("Programming-Language", "Kotlin"))
    )
}

s.get("/file") {
    println(it.path)
    return@get FileResponse(Server::class.java.getResource("/happyx.dll")!!.file)
}

s.start()
@Ethosa Ethosa added the enhancement New feature or request label Dec 6, 2023
@Ethosa Ethosa self-assigned this Dec 6, 2023
@Ethosa Ethosa pinned this issue Dec 6, 2023
Ethosa added a commit that referenced this issue Dec 7, 2023
Ethosa added a commit that referenced this issue Dec 9, 2023
Ethosa added a commit that referenced this issue Dec 11, 2023
@Ethosa Ethosa unpinned this issue Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language bindings
Projects
None yet
Development

No branches or pull requests

1 participant