Replies: 3 comments 6 replies
-
See https://disneystreaming.github.io/smithy4s/docs/protocols/simple-rest-json/overview#semantics The protocol specifically only issue
I will see So:
The request looks like this:
But if you're telling us that the following works (json payload with a different content-type):
Then you can probably implement this via a middleware. Just let us know and I'd be happy to show you |
Beta Was this translation helpful? Give feedback.
-
To be clear: you want to build a server (using smithy4s) that accepts this requests:
Correct? (I ask because I had the impression you were trying to use the client but now I think I was wrong and you're trying to implement the service side of this) |
Beta Was this translation helpful? Give feedback.
-
Without implementing a new protocol, you can work around this (not recommended, but it should work) by making your own object MyRestJsonBuilder
extends SimpleProtocolBuilder[smithy4s.api.SimpleRestJson](
// notable change from the definition of `SimpleRestJsonBuilder`
CodecAPI.nativeStringsAndBlob(
//
smithy4s.http.json.codecs(
smithy4s.api.SimpleRestJson.protocol.hintMask ++ HintMask(InputOutput)
)
)
)
object Main extends ResourceApp.Forever {
val impl: ReportService[IO] = new ReportService[IO] {
def report(payload: RawPayload): IO[Unit] = IO.println(payload.value)
}
def run(args: List[String]): Resource[IO, Unit] =
MyRestJsonBuilder
.routes(impl)
.resource
.map(_.orNotFound)
.flatMap(
EmberServerBuilder
.default[IO]
.withHttpApp(_)
.withPort(port"8080")
.withHost(host"0.0.0.0")
.build
)
.void
} Then annotating your payload with
Do note the following though:
|
Beta Was this translation helpful? Give feedback.
-
I have a request like this
Due to the origin of this request, nothing can be done to change it to use json content-type. Regardless, I have a schema like this
When I submit the request above with double quotes around the body, then it works. But if I remove the double quotes, then I get 500, as expected because the body does not confirm to json format. I then tried changing the
payload
to Blob instead of String, and I get 500 error regardless.How should I handle this case?
Beta Was this translation helpful? Give feedback.
All reactions