Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active February 19, 2021 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamw/569a6055a4ffdad2ec4aa272a18f0902 to your computer and use it in GitHub Desktop.
Save adamw/569a6055a4ffdad2ec4aa272a18f0902 to your computer and use it in GitHub Desktop.
trait TapirHandler extends RequestStreamHandler {
def endpoints: List[ServerEndpoint[_, _, _, Any, Identity]]
override def handleRequest(input: InputStream, output: OutputStream,
context: Context): Unit = {
val json = new String(input.readAllBytes(), UTF_8)
val writer = new BufferedWriter(new OutputStreamWriter(output, UTF_8))
writer.write(handleRequest(json))
writer.flush()
}
def handleRequest(input: String): String = {
val resp = decode[AwsRequest](input) match {
case Left(error) => AwsResponse(Nil, isBase64Encoded = false,
StatusCode.BadRequest.code, Map.empty,
error.getMessage)
case Right(req) => AwsServerInterpreter(req, endpoints)
}
Printer.noSpaces.print(resp.asJson)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment