feat(api): expose HTTP REST endpoints for DID resolution, mailbox relay, and health

Open
#3 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
api

Research direction

Start in src/main.rs, where the node builds NodeConfig, MailboxStore and KeyTransparencyLog and prints a health line before exiting, then look at src/health.rs, src/merkle.rs and src/relay.rs for the data they expose. The new router belongs in src/http_server.rs, which must stay under 300 lines. Check docs/API.md for the response schemas and tests/node_test.rs for the existing tests, which must keep passing. Done means all five endpoints return the documented status codes and JSON, and fmt, clippy and test pass.

Written by the indexing model from the issue text.

Description

area::node effort::l impact::critical priority::critical source::user status::review type::feature

Part of Meta-Issue alfonsodg/sonaraim#2
Ref alfonsodg/sonaraim-node#2

Problem

src/main.rs:1-34 currently initializes NodeConfig, MailboxStore, and KeyTransparencyLog, prints a single JSON health line to stdout, and exits. It does not bind an HTTP listener on NODE_HTTP_HOST:NODE_HTTP_PORT (8040) to serve the documented REST endpoints (GET /health, POST /v1/identity, GET /v1/identity/{did}, POST /v1/relay/envelopes, GET /v1/relay/mailboxes/{mailbox_id}).

Affected Files & Locations

  • src/main.rs:1-34
  • src/health.rs:1-75
  • src/merkle.rs:42-269
  • src/relay.rs:34-127
  • src/http_server.rs (new HTTP server & router module, < 300 lines)
  • tests/node_test.rs:1-167

Evidence

// src/main.rs:27-33
let health = HealthStatus::new(&config.node_id, "0.1.0", 0, log.tree_size());
println!("{}", health.to_json());

Impact and Blast Radius

sonaraim-b2b, sonaraim-admin, and sonaraim-app depend on sonaraim-node's HTTP API (8040) to register and resolve DIDs, verify Merkle inclusion proofs, publish SealedEnvelope messages, and drain recipient mailboxes.

Historical Context and Anti-Regression

Builds on e62fca0 (Issue #1). All 5 existing unit tests in tests/node_test.rs must continue passing without modification.

Proposed Solution

  1. Implement src/http_server.rs exposing:
    • GET /health -> 200 OK
    • POST /v1/identity -> 201 Created (registers did:sonaraim or did:web and returns Merkle proof)
    • GET /v1/identity/{did} -> 200 OK / 404 Not Found
    • POST /v1/relay/envelopes -> 202 Accepted (stores SealedEnvelope and returns wake_up_token)
    • GET /v1/relay/mailboxes/{mailbox_id} -> 200 OK (drains active envelopes for mailbox)
  2. Standardize error responses using {"error": {"code": "...", "message": "..."}}.

Acceptance Criteria

  • HTTP server binds to configured NODE_HTTP_HOST:NODE_HTTP_PORT (or ephemeral port 0 in tests).
  • Every exposed endpoint and HTTP method (GET /health, POST /v1/identity, GET /v1/identity/{did}, POST /v1/relay/envelopes, GET /v1/relay/mailboxes/{mailbox_id}) is tested with valid and invalid payloads (200, 201, 202, 400, 404, 405).
  • All files remain under 300 lines and pass cargo fmt --check, cargo clippy -- -D warnings, and cargo test.

Validation Criteria

Level Applies Test Scenario Pass
Unit Yes tests/node_test.rs Request parsing, route dispatch, error formatting 100% pass (cargo test)
Integration Yes tests/node_test.rs Live TCP HTTP requests exercising all 5 endpoints and methods Status codes and JSON bodies verified
Contract Yes docs/API.md Response JSON structure matches docs/API.md specification 100% schema match
E2E Yes curl verification on Sandbox (REMOTE.md) Live HTTP requests against running sonaraim-node container HTTP 200/201/202 verified
Dominant language
Rust
Stars
0
Forks
0
Avg merge
4m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from alfonsodg/sonaraim-node

All issues in alfonsodg/sonaraim-node

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.