Skip to content

feat(br_server): add REST API discovery endpoint (/.well-known/thread/esp-br-rest) - #216

Closed
lboue wants to merge 1 commit into
espressif:mainfrom
lboue:feature/rest-api-well-known-discovery
Closed

feat(br_server): add REST API discovery endpoint (/.well-known/thread/esp-br-rest)#216
lboue wants to merge 1 commit into
espressif:mainfrom
lboue:feature/rest-api-well-known-discovery

Conversation

@lboue

@lboue lboue commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Summary

Adds a REST API discovery endpoint and a tracked version number for esp-thread-br's own REST API, inspired by ot-br-posix's discovery endpoint but adapted to the fact that the two implementations do not expose the same REST API contract. Closes #215.

  • GET /.well-known/thread/esp-br-rest — RFC 8615 well-known URI returning the running REST API's version and RFC 8288-style links to its entry points, so clients can discover capabilities at runtime instead of hardcoding/probing endpoint paths. Inspired by ot-br-posix's endpoint ([rest] add REST API version in /.well-known/thread for API discovery openthread/ot-br-posix#3330), but served on its own esp-thread-br-specific path (rather than ot-br-posix's /.well-known/thread/br-rest) so clients that need to support both APIs can probe each implementation's own well-known path to disambiguate them.
  • ESP_OT_REST_API_VERSION (in esp_br_web_api.h) — new single source of truth for the REST API's semver version, analogous to ot-br-posix's src/rest/version.hpp. Versioned independently from ot-br-posix's OTBR_REST_API_VERSION, since the two implementations' REST surfaces differ (different base path, and ot-br-posix has endpoints — actions, devices, JSON:API diagnostics, commissioner, coprocessor-version — that esp-thread-br doesn't implement).
  • Bumped openapi.yaml's info.version (and ESP_OT_REST_API_VERSION) to 1.1.0: 1.0.0 was the pre-existing baseline, and 1.1.0 accounts for the ePSKc endpoints (/node/ba-epskc/state, /node/ba-epskc/key) added since then without a version bump.
  • tools/ci/check_rest_api_version_sync.py, wired into .pre-commit-config.yaml, fails if ESP_OT_REST_API_VERSION and openapi.yaml's info.version ever drift apart.
  • components/esp_ot_br_server/CHANGELOG.md tracks the REST API's version history going forward.

Why

This component reimplements part of the same REST surface as ot-br-posix but had no way for a client to discover the API version or capabilities at runtime, and its OpenAPI info.version had never been bumped even across earlier additive endpoint changes. See #215 for the discussion.

Going forward

Bump ESP_OT_REST_API_VERSION and openapi.yaml's info.version together whenever a REST endpoint is added/changed, following semver (MAJOR = breaking, MINOR = backward-compatible addition, PATCH = bug fix), and record the change in components/esp_ot_br_server/CHANGELOG.md. check_rest_api_version_sync.py enforces the two version fields stay in sync.

Testing

  • openapi.yaml validated with python3 -c "import yaml; yaml.safe_load(open(...))".
  • tools/ci/check_rest_api_version_sync.py run locally, including a forced-mismatch case to confirm it fails as expected.

Comment thread components/esp_ot_br_server/src/openapi.yaml Outdated
cJSON *response = cJSON_CreateObject();
ESP_RETURN_ON_FALSE(response, ESP_FAIL, WEB_TAG, "Failed to allocate well-known response");

cJSON *api = cJSON_CreateObject();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the api pointer is NULL before we use it.

Comment thread components/esp_ot_br_server/private_include/esp_br_web_version.h Outdated
@lboue

lboue commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed feedback @zwx1995esp!

I agree. Starting at 1.0.0 for ESP_OT_REST_API_VERSION makes sense, since esp-thread-br doesn't currently expose the same REST surface as ot-br-posix (no /api/ base path, no actions/devices/JSON:API diagnostics/commissioner/coprocessor-version endpoints). Tying the number to ot-br-posix's version was misleading given the surfaces diverge. I'll switch to 1.0.0 and version it independently going forward per the semver policy already described in the PR.

On the ESP_OT_REST_API_VERSION / openapi.yaml drift concern: I'll add a CI check that fails if the two values are out of sync, rather than just documenting that they're allowed to differ.

One related thought for down the line: python-otbr-api recently added get_api_version() (home-assistant-libs/python-otbr-api#271) as groundwork for eventually feature-gating on the REST API version instead of reactive 404 handling. It's not wired up to any actual feature detection yet.
ePSKc support detection (home-assistant-libs/python-otbr-api#267) still uses a direct 200/404 probe on the endpoint, which is the safer approach regardless of implementation. But if/when a client ever does start comparing version numbers for feature-gating, two implementations independently versioned from 1.0.0 could look identical at a given number while exposing different surfaces. Not something to solve now, but might be worth an "implementation" field in the discovery response at some point so clients can disambiguate if they ever need to.

Will also fix the NULL check on api and fold the version macro into esp_br_web_api.h as suggested.

@agners

agners commented Aug 20, 2026

Copy link
Copy Markdown

Not something to solve now, but might be worth an "implementation" field in the discovery response at some point so clients can disambiguate if they ever need to.

That, or use an entirely different versioning endpoint, e.g. /.well-known/thread/esp-br-rest. Libraries which intend to support both BR REST APIs can then check both endpoints.

lboue added a commit to lboue/esp-thread-br that referenced this pull request Aug 20, 2026
Address two review comments on the REST API discovery endpoint:

- Serve the discovery endpoint on its own esp-thread-br-specific
  well-known path (/.well-known/thread/esp-br-rest) instead of
  ot-br-posix's (/.well-known/thread/br-rest), since the two
  implementations do not expose the same REST API contract. This lets
  clients that support both APIs probe each implementation's own path
  to disambiguate them, per agners' suggestion
  (espressif#216 (comment)).

- Fold ESP_OT_REST_API_VERSION into esp_br_web_api.h and drop the
  now-unneeded esp_br_web_version.h, per zwx1995esp's suggestion
  (espressif#216 (comment)).

Also add a missing NULL check on the "api" cJSON object in the
discovery handler.
lboue added a commit to lboue/esp-thread-br that referenced this pull request Aug 20, 2026
…in sync

Address zwx1995esp's remaining review comment
(espressif#216 (comment)):

- esp-thread-br and ot-br-posix do not currently expose the same REST
  API contract (different base path, and ot-br-posix has endpoints
  esp-thread-br does not implement), so ESP_OT_REST_API_VERSION should
  not mirror ot-br-posix's version. Start it, and openapi.yaml's
  info.version, at 1.0.0 and version esp-thread-br's REST API
  independently from here on.

- Add tools/ci/check_rest_api_version_sync.py, wired into
  .pre-commit-config.yaml, to fail if ESP_OT_REST_API_VERSION and
  openapi.yaml's info.version ever drift apart.
lboue added a commit to lboue/esp-thread-br that referenced this pull request Aug 20, 2026
Keep the rationale for the esp-br-rest well-known path in the code
comments, but drop the link to the specific review comment
(espressif#216 (comment)) —
it doesn't belong as a permanent reference in the source.
@lboue lboue changed the title feat(br_server): add REST API discovery endpoint (/.well-known/thread/br-rest) feat(br_server): add REST API discovery endpoint (/.well-known/thread/esp-br-rest) Aug 20, 2026
@lboue
lboue requested a review from zwx1995esp August 20, 2026 19:06
@lboue

lboue commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks both for the review! Pushed changes addressing each point:

  • Discovery endpoint path (comment, @agners): moved off ot-br-posix's /.well-known/thread/br-rest onto an esp-thread-br-specific /.well-known/thread/esp-br-rest, since the two implementations don't expose the same REST API contract. Clients supporting both can now probe each implementation's own well-known path to disambiguate, instead of needing an "implementation" field in the response. (2bd931c)

  • NULL check on api (comment, @zwx1995esp): added. (2bd931c)

  • Drop the extra file for the version macro (comment, @zwx1995esp): ESP_OT_REST_API_VERSION moved into esp_br_web_api.h; esp_br_web_version.h removed. (2bd931c)

  • Independent REST API versioning + avoid version drift (comment, @zwx1995esp):

    • ESP_OT_REST_API_VERSION no longer mirrors ot-br-posix's OTBR_REST_API_VERSION; esp-thread-br now tracks its own REST API version, starting from 1.0.0 (ce94ded).
    • Added tools/ci/check_rest_api_version_sync.py, wired into .pre-commit-config.yaml, to fail if ESP_OT_REST_API_VERSION and openapi.yaml's info.version ever drift apart (ce94ded).
    • Realized openapi.yaml was already at 1.0.0 before the ePSKc endpoints were added without a version bump, so bumped to 1.1.0 (MINOR, new backward-compatible endpoints) to account for that (2ba483a).
    • Added components/esp_ot_br_server/CHANGELOG.md to track REST API version history going forward (7c051f3).

@zwx1995esp
zwx1995esp requested a review from chshu August 24, 2026 07:03

@zwx1995esp zwx1995esp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread components/esp_ot_br_server/src/esp_br_web.c Outdated
lboue added a commit to lboue/esp-thread-br that referenced this pull request Aug 28, 2026
Address zwx1995esp's remaining review comment on PR espressif#216
(espressif#216 (comment)):
drop implementation details, the br-rest/esp-br-rest naming rationale, and
the historical justification from the discovery endpoint's doc comments in
esp_br_web.c and esp_br_web_api.h, keeping only what a user of the API needs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@lboue
lboue requested a review from zwx1995esp August 28, 2026 20:02

@zwx1995esp zwx1995esp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @lboue I think we can simplify the docs and remove some redundant description. And could you please squash the 7 commits into 1? I think this PR will be ready after fixing those.

ESP Thread Border Router Wer Server REST API
----------------------------------------------------------------------*/
/* HTTP GET */
/* RFC 8615 well-known URI for REST API discovery: reports the running API version and links to its

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the line 42 and 43. I think we have already explained this at the line 828

tags:
- discovery
summary: Discover the REST API version and entry points
description: |-

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this description, since we have already explained the details in the file esp_br_web.c.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

[Semantic Versioning](https://semver.org/): MAJOR for incompatible API changes, MINOR for
backward-compatible additions, PATCH for backward-compatible fixes.

esp-thread-br versions its REST API independently from ot-br-posix's `OTBR_REST_API_VERSION`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the line from 8 to 10.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

…/esp-br-rest)

Add a REST API discovery endpoint and a tracked version number for
esp-thread-br's own REST API.

- GET /.well-known/thread/esp-br-rest: RFC 8615 well-known URI returning
  the running REST API's version and RFC 8288-style links to its entry
  points, so clients can discover capabilities at runtime instead of
  hardcoding/probing endpoint paths. Served on its own esp-thread-br-specific
  path so clients that need to support both esp-thread-br's and
  ot-br-posix's REST APIs can probe each implementation's own well-known
  path to disambiguate them.
- ESP_OT_REST_API_VERSION (in esp_br_web_api.h): single source of truth
  for the REST API's semver version, starting at 1.0.0 and versioned
  independently from ot-br-posix's OTBR_REST_API_VERSION, since the two
  implementations' REST surfaces differ.
- Bump openapi.yaml's info.version (and ESP_OT_REST_API_VERSION) to
  1.1.0, accounting for the ePSKc endpoints (/node/ba-epskc/state,
  /node/ba-epskc/key) added since the 1.0.0 baseline without a version
  bump.
- tools/ci/check_rest_api_version_sync.py, wired into
  .pre-commit-config.yaml, fails if ESP_OT_REST_API_VERSION and
  openapi.yaml's info.version ever drift apart.
- components/esp_ot_br_server/CHANGELOG.md tracks the REST API's
  version history going forward.

Closes espressif#215.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@lboue
lboue force-pushed the feature/rest-api-well-known-discovery branch from d6cccd4 to 4f1d409 Compare August 31, 2026 11:19
@lboue
lboue requested a review from zwx1995esp August 31, 2026 11:21
@zwx1995esp

Copy link
Copy Markdown
Collaborator

Merged here: ff0d1e3

@zwx1995esp zwx1995esp closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REST API: add /.well-known/thread/br-rest discovery endpoint (mirroring ot-br-posix)

3 participants