SatCat5
coap_resource.h File Reference

Detailed Description

CoAP resource handler definition and resource server creation.

The coap::Resource base class is derived to create different types of handlers for CoAP GET, POST, PUT, and DELETE requests registered to respond to a given URI specified by one or more Uri-Path CoAP request options. Each Resource is registered to a URI that MUST be unique and should not contain any leading or trailing slashes. Two examples are included: coap::ResourceEcho responds to any GET request with a copy of its payload and coap::ResourceLog will create a Log entry from the payload of any incoming POST request.

One or more Resources can be added to a coap::ResourceServer class, which acts as a CoAP server to route requests to the correct coap::Resource according to the Uri-Path option. While not recommended, a Resource can be registered to the server root and therefore accessible without any Uri-Path options by declaring the path string to be "".

There are a few important notes to keep in mind when declaring URIs:

  • Resource Uri-Paths may optionally include one leading slash but MUST NOT include tailing slashes.
    • Valid examples: "top1/nested2/target3" or "/top1/nested2/target3".
    • Violating this WILL cause a lookup failure in ResourceServer.
  • Uri-Host, Uri-Port, and Uri-Query are not implemented and their inclusion WILL trigger an error since these are Critical options. Host and Port are implicit from lower-layer routing, and Query options are not supported.
  • Nested paths are supported; however, this is a simple URI string match.
  • There is a compile-time maximum length for the fully assembled URI string (SATCAT5_COAP_MAX_URI_PATH_LEN) that MUST NOT be violated in the given Uri-Path, else the Resource can never be matched.

Definition in file coap_resource.h.

#include <satcat5/coap_connection.h>
#include <satcat5/coap_endpoint.h>
#include <satcat5/utils.h>
Include dependency graph for coap_resource.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  satcat5::coap::Resource
 Define a single CoAP resource. More...
 
class  satcat5::coap::ResourceEcho
 Resource that echos back any incoming payload. More...
 
class  satcat5::coap::ResourceError
 Resource that returns a fixed status code for all requests. More...
 
class  satcat5::coap::ResourceLog
 Resource that creates a log::Log entry. More...
 
class  satcat5::coap::ResourceNull
 The NullResource does not implement GET, POST, PUT, or DELETE. More...
 
class  satcat5::coap::ResourceServer
 Manager for several Resource objects available on an Endpoint. More...