Last active
February 19, 2021 17:16
-
-
Save adamw/569a6055a4ffdad2ec4aa272a18f0902 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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