Skip to content

RE: Fix /api/v1 prefix consistency and add a root resource to the REST API - #112

Merged
jlegrand62 merged 9 commits into
devfrom
feature/deploy-prefix-support
Sep 2, 2026
Merged

jlegrand62 merged 9 commits into
devfrom
feature/deploy-prefix-support

Conversation

@ArthurLuciani2

Copy link
Copy Markdown
Contributor

PR Summary

Problem

Two related issues in the PlantDB REST API:

  1. Inconsistent /api/v1 prefixing. Endpoint paths and the URLs embedded in server responses were not consistently including the /api/v1 mount prefix, and there was no clean separation between the API version prefix and a deployment (reverse-proxy) path prefix.
  2. Missing resource at the server root. A request to the bare root (http://host:port/, or http://host:port/{prefix}/ behind a proxy) returned 404, because all resources are mounted under /api/v1.

Solution

Introduce two distinct prefix concepts and thread them everywhere:

  • API_PREFIX = "/api/v1" — always present, shared truth. The app mounts at /api/v1 only.
  • Deployment prefix (deploy_prefix, e.g. /plantdb) — a runtime per-server/per-client constant for reverse-proxy deployments, used only to generate external-facing URLs in responses.

Server

  • api_endpoints: the @api_prefix decorator now composes <deploy_prefix>/api/v1/<endpoint> (with proper sanitization) and the Home resource builds its endpoint map via these builders.
  • fsdb_rest_api / wsgi: mount at /api/v1 always; deploy_prefix replaces the deprecated api_prefix param; the --api-prefix / API_PREFIX value is honored.
  • Scan services (get_scan_info / get_scan_data) and _get_colmap_camera_model thread the prefix into every generated URL (archive, thumbnail, filesUri, camera poses). This fixes two bugs where camera-pose URLs and the nested get_scan_info output lost the prefix.
  • Root resource: register a 302 redirect at / to the home endpoint, keeping the deployment prefix in the Location header so clients stay under the proxy path.

Client

  • PlantDBClient stores self.prefix and threads it into every api_endpoints.* call.
  • URL builders (login_url, scan_url, scan_image_url, …) build fully-prefixed URLs; plantdb_url() now returns the server root including the deployment prefix but not /api/v1.

Tests

  • test_api_endpoints.py — deployment-prefix composition across all endpoint builders (78 subtests).
  • test_scan_services.py — prefix threading through scan info/data services.
  • test_rest_api_deploy_prefix.py — server responses embed the deployment prefix (Home map, ScansTable, Scan).
  • test_rest_api_server.py — root-redirect tests (no-prefix and /plantdb cases, exact Location, follow-redirect).
  • test_rest_api.py — updated client URL assertions for /api/v1 and the root plantdb_url behavior.

Notes

  • test_server_availability() now passes via the new root redirect (GET / → 302 → /api/v1/).
  • Existing client and server suites pass; the remaining untracked files (knowledge/, test data, caches) are local artifacts not part of this PR.

A request to the bare server root (http://host:port/ or the reverse-proxy
root http://host:port/{prefix}/) previously returned 404, because all
resources are mounted under the /api/v1 prefix. Register a lightweight
route at "/" that issues a 302 redirect to the home endpoint, keeping the
deployment (reverse-proxy) prefix in the generated Location so clients
stay under the proxy path.

- fsdb_rest_api.py: add _register_root_redirect() helper that maps the
  root path to home(prefix=deploy_prefix) and wire it into rest_api() so
  both the fsdb_rest_api CLI and the WSGI entrypoint (wsgi.py) expose the
  redirect, honoring the --api-prefix / API_PREFIX value.
- test_rest_api_server.py: add RootRedirectTests covering the no-prefix
  and /plantdb-prefix cases (asserting the 302 and exact Location header)
  plus a follow-redirect check that lands on the Home payload.
@ArthurLuciani2 ArthurLuciani2 self-assigned this Sep 2, 2026
@ArthurLuciani2 ArthurLuciani2 added bug Something isn't working enhancement New feature or request labels Sep 2, 2026
- Remove leading spaces before `>>>` prompts to clean up doctest formatting in `urls.py`
- Update `refresh` signature to `def refresh(scan_id: str | None = None, **kwargs) -> str` and adjust its docstring to "str or None, optional"
- Insert a blank line after the `urllib` import for consistency
- Remove the stray blank line preceding the `refresh` definition
- Reformat parameter indentation in `fileset_metadata`, `file_metadata`, `image`, `pointcloud`, and `mesh` for clearer readability
- Minor docstring wording updates (e.g., `key : str or None, optional`)
@jlegrand62
jlegrand62 merged commit 68ddac3 into dev Sep 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants