readBody

inline fun <T> Request.readBody(bodyDeserializer: DeserializationStrategy<T> = serializer()): T?(source)

A serialization-aware convenience method layered on top of Request.readBodyText.

If no body is set, this will return null. However, an exception will be thrown if the body type cannot be deserialized (either due to body text that is not valid JSON or valid JSON that cannot be converted into the requested type).

See also the ApiFetcher extension methods provided by this library for examples of how to send requests with a serialized body, e.g. window.api.post<ExampleRequest, ExampleResponse>(body = ...).