Companion

Functions

Link copied to clipboard

2.04 Changed (RFC 7252 §5.9.1.4).

Link copied to clipboard
fun content(payload: ByteArray, contentFormat: Int? = null): CoapResponse

2.05 Content with payload in contentFormat.

fun content(text: String, contentFormat: Int = ContentFormat.TEXT_PLAIN): CoapResponse

2.05 Content with UTF-8 text, text/plain unless another contentFormat is given.

Link copied to clipboard
fun created(vararg locationPath: String): CoapResponse

2.01 Created (RFC 7252 §5.9.1.1), with the Location-Path of the new resource.

Link copied to clipboard

2.02 Deleted (RFC 7252 §5.9.1.2).

Link copied to clipboard
fun error(code: CoapCode, diagnostic: String? = null): CoapResponse

An error response; diagnostic becomes the RFC 7252 §5.5.2 diagnostic payload, which is UTF-8 text for developers and SHOULD be empty when it adds nothing to the code.

Link copied to clipboard

The response message carries: its code, options and payload, without the messaging-layer fields.

Link copied to clipboard
fun tooManyRequests(retryAfter: Duration, diagnostic: String? = null): CoapResponse

4.29 Too Many Requests (RFC 8516 §3), for a client that sends requests more often than the server can or will handle: its Max-Age is retryAfter in whole seconds, rounded up so the client never comes back too early, and at most 2^32 - 1 (RFC 7252 §5.10.5); the client should not send a similar request before that (RFC 8516 §4). diagnostic becomes the diagnostic payload (RFC 7252 §5.5.2), which may say more about the overload. RFC 8516 §3 keeps 4.29 for the clients that send too often; an overload that all clients cause gets 5.03 Service Unavailable, with Max-Age as well.