ResourceBuilder
Defines resources inline, as an alternative to subclassing CoapResource:
val server = CoapServer(endpoint) {
resource("sensors") {
resource("temp") {
attributes = ResourceAttributes(resourceTypes = listOf("temperature-c"))
observable()
get { CoapResponse.content(readTemperature()) }
}
}
resource("echo") { post { CoapResponse(CoapCode.CHANGED, payload = payload) } }
resource("api") {
access = AccessPolicy.Authenticated // for /api and everything below it
resource("config") { put { CoapResponse.changed() } }
}
add(FirmwareResource())
}A resource without handlers only groups children: it answers 4.04 and is not listed in /.well-known/core. One with handlers answers 4.05 for the other methods.
Properties
Who may use the resource and the resources below it without a policy of their own (ADR 0008); null, the default, inherits the parent's. At the top level of the server's routes it is the root's, which governs every resource that sets none. See AccessPolicy.
Link attributes for /.well-known/core.
Whether /.well-known/core lists the resource (when it has handlers).
Functions
Adds a subclassed resource as a child.
Handles DELETE (RFC 7252 §5.8.4).
Handles FETCH (RFC 8132 §2).
Handles GET (RFC 7252 §5.8.1); for an observable resource also every notification.
Handles iPATCH (RFC 8132 §3).
Makes the resource observable (RFC 7641) with notifications of type.
Handles method, for methods without a shortcut.
Handles PATCH (RFC 8132 §3).
Handles POST (RFC 7252 §5.8.2).
Handles PUT (RFC 7252 §5.8.3).
Critical options the handlers process themselves (see CoapResource.recognizedOptions).
Adds a child defined by block and returns it, for example to call ObservableResource.notifyObservers.