Created
September 24, 2019 10:36
-
-
Save tyrcho/23fb831e04e803c093d1a5860f67411f to your computer and use it in GitHub Desktop.
Demo of a mock HTTP server in scala (uses ammonite)
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 $ivy.`com.squareup.okhttp:mockwebserver:2.5.0` | |
import com.squareup.okhttp.mockwebserver._ | |
val ws = new MockWebServer | |
ws.start() | |
val url = ws.url("/test") | |
println(url) | |
val response = new MockResponse | |
response.setBody( """ { "key" : "value" } """) | |
response.setHeader("content-type", "application/json") | |
ws.enqueue(response) | |
val resp=requests.post(url.toString, | |
headers = Map("Content-Type" -> "application/json"), | |
data = ujson.Obj("email" -> "[email protected]").render()) | |
println(resp.text) | |
val request = ws.takeRequest() | |
println(request.getHeaders) | |
println(request.getPath) | |
println(request.getMethod) | |
println(request.getBody.readUtf8) | |
ws.shutdown() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment