Protocol: nabto.http/1

The nabto.http/1 protocol allows clients to forward HTTP requests through Cambridge to configured HTTP services. This is typically used for camera management APIs, for example retrieving snapshots, changing settings or querying device status.

Open a datachannel with the protocol "nabto.http/1". The datachannel label can be picked arbitrarily:

const channel = pc.createDataChannel("http", {
    protocol: "nabto.http/1",
});

Constraints

The HTTP protocol has the following limitations:

  • No duplicate headers. Each header name may appear at most once in a request or response.
  • No chunked transfer encoding. Requests and responses must fit in a single message.
  • Maximum message size is 64 kB. Requests or responses exceeding this limit will result in an error.

http.listServices

Lists the HTTP services configured on the device (defined in services.http configuration tables).

Request

{
  "jsonrpc": "2.0",
  "method": "http.listServices",
  "id": "1234"
}

Response

{
  "jsonrpc": "2.0",
  "result": {
    "services": [
      {
        "name": "my_endpoint",
        "description": "A test HTTP endpoint"
      }
    ]
  },
  "id": "1234"
}

Each entry contains:

FieldTypeDescription
namestringService name, used in the service parameter of http.request
descriptionstringHuman-readable description from the configuration

http.request

Forwards an HTTP request to a configured service.

Request

{
  "jsonrpc": "2.0",
  "method": "http.request",
  "params": {
    "service": "my_endpoint",
    "method": "GET",
    "target": "/api/hello",
    "headers": {
      "Authorization": "Bearer token123",
      "X-Custom-Header": "value"
    },
    "body": "base64-encoded-request-body"
  },
  "id": "5678"
}

Parameters

ParameterRequiredTypeDescription
serviceYesstringHTTP service name from the device configuration
methodYesstringHTTP method (GET, POST, PUT, DELETE, etc.)
targetYesstringRequest path (e.g., /api/hello)
headersNoobjectRequest headers as key-value pairs
bodyNostringBase64-encoded request body

Response

{
  "jsonrpc": "2.0",
  "result": {
    "status": 200,
    "headers": {
      "content-type": "application/json",
      "x-custom-response": "value"
    },
    "body": "base64-encoded-response-body"
  },
  "id": "5678"
}
FieldTypeDescription
statusnumberHTTP status code
headersobjectResponse headers as key-value pairs
bodystring (optional)Base64-encoded response body, omitted if empty

http.cancel

Cancels an in-flight HTTP request. This is a JSON-RPC notification, so no response is sent. The params value is the id of the request to cancel.

{
  "jsonrpc": "2.0",
  "method": "http.cancel",
  "params": "5678"
}

If the cancelled request has not yet completed, the original request will return a JSON-RPC error with code -32001.

Error Codes

In addition to standard JSON-RPC errors, the HTTP protocol defines:

CodeMessageDescription
-32000Generic errorAn error occurred, more information can be found in the description field of the error object
-32001Request cancelledThe request was cancelled by an http.cancel notification
-32002Service not foundRequested service is not configured on the device
-32003Gateway timeoutCould not connect to upstream or request timed out
-32004Response too largeThe HTTP response exceeded the 256 kB maximum message size