Module

Yoga.Fastify.Om.RequestBody

Package
purescript-yoga-fastify-om
Repository
rowtype-yoga/purescript-yoga-fastify-om

#RequestBody Source

data RequestBody a

Sum type representing different request body formats

Handlers receive wrapped RequestBody values and pattern match on them.

Example usage: type MyRequest = { body :: JSONBody CreateUserRequest }

handler { request } = case request.body of JSONBody user -> createUser user NoBody -> error "No body provided"

Constructors

Instances

#toStrom Source

toStrom :: forall a ctx err. RequestBody a -> Strom ctx err Buffer

Convert a RequestBody to a Strom of Buffers for streaming processing.

  • BytesBody: emits the buffer as a single chunk
  • StreamBody: streams chunks from the ReadableStream
  • TextBody: converts the string to a Buffer and emits it
  • JSONBody/FormData/NoBody: emits nothing (empty stream)

Example: handler { request } = do let stream = toStrom request.body Strom.runFold (\acc chunk -> acc + Buffer.size chunk) 0 stream