Created
October 29, 2023 09:00
-
-
Save s4nchez/770f54d153cc9f2e01e3f93fc526744f to your computer and use it in GitHub Desktop.
Example of http4k server and client
This file contains 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 org.http4k.client.JavaHttpClient | |
import org.http4k.core.Method | |
import org.http4k.core.Request | |
import org.http4k.core.then | |
import org.http4k.filter.DebuggingFilters.PrintResponse | |
fun main() { | |
val client = JavaHttpClient() | |
val printingClient = PrintResponse().then(client) | |
printingClient(Request(Method.GET, "http://localhost:9000/ping")) | |
} |
This file contains 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 org.http4k.core.Request | |
import org.http4k.core.Response | |
import org.http4k.core.Status.Companion.OK | |
import org.http4k.server.SunHttp | |
import org.http4k.server.asServer | |
fun main() { | |
val server = { _: Request -> Response(OK).body("pong") } | |
server.asServer(SunHttp(9000)).start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment