post

inline suspend fun <B, R> HttpFetcher.post(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: B? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null, bodySerializer: SerializationStrategy<B> = serializer(), responseDeserializer: DeserializationStrategy<R> = serializer()): R(source)

Call POST on a target resource with B as the body type and R as the expected return type.

See also tryPost, which will return null if the request fails for any reason.

Parameters

body

The body to send with the request. Make sure your class is marked with @Serializable or provide a custom bodySerializer. Note that JSON is used as the serialization format, and if body is non-null, the Content-type will automatically be set to application/json (unless explicitly set by the user).


inline suspend fun <R> HttpFetcher.post(resource: String, headers: Map<String, Any>? = FetchDefaults.Headers, body: ByteArray? = null, redirect: RequestRedirect? = FetchDefaults.Redirect, abortController: AbortController? = null, responseDeserializer: DeserializationStrategy<R> = serializer()): R(source)

A serialize-friendly version of post that doesn't put any type constraints on the body.

This is useful if your request doesn't require a body to be included, so there shouldn't be a need to specify a body type constraint in that case, or if it is easier to use a custom, handcrafted byte array message instead.