GoldenGateBindings / com.fitbit.goldengate.bindings.coap.handler / ResourceHandler

ResourceHandler

interface ResourceHandler

A user of this API will implement this interface and register it with an Endpoint. The user can then expect each of these methods to be called when an appropriate request is received.

Example:

class SimpleResourceHandler : ResourceHandler {
    override fun onGet(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse> {
        //examine request if desired
        val bodyData: ByteArray = ....
        return Single.just(
                responseBuilder.responseCode(ResponseCode(2, 5)).body(BytesArrayOutgoingBody(bodyData)).build()
        )
    }

    override fun onPost(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse> {
        val bodyData = request.body.asData.blockingGet()
        //process body data.
        return Single.just(
                responseBuilder.responseCode(ResponseCode(2, 1)).build()
        )
    }

    override fun onPut(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse> {
        val bodyData = request.body.asData.blockingGet()
        //process body data.
        return Single.just(
                responseBuilder.responseCode(ResponseCode(2, 4)).build()
        )
    }

    override fun onDelete(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse> {
        return Single.just(
                responseBuilder.responseCode(METHOD_NOT_ALLOWED_RESPONSE_CODE).build()
        )
    }
}

Functions

onDelete

abstract fun onDelete(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse>

Handler for request of DELETE

onGet

abstract fun onGet(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse>

Handler for request of GET

onPost

abstract fun onPost(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse>

Handler for request of POST

onPut

abstract fun onPut(request: IncomingRequest, responseBuilder: OutgoingResponseBuilder): Single<OutgoingResponse>

Handler for request of PUT

Inheritors

BaseResourceHandler

open class BaseResourceHandler : ResourceHandler

Base Implementation for ResourceHandler providing request not supported implementation for all resource handler.