Skip to content

feat(backend, http): add HTTP API for ADJ catalogs and WebSocket upgrade support - #676

Open
pminmic wants to merge 20 commits into
new-backendfrom
backend/http
Open

pminmic wants to merge 20 commits into
new-backendfrom
backend/http

Conversation

@pminmic

@pminmic pminmic commented Nov 13, 2026

Copy link
Copy Markdown

Features

software-core

  • New http feature:
    • Serializable response models for data, order, and protection catalogs.
    • JSON examples in src/adj/http/example/.
    • New Adj methods to build the response catalogs.
  • New crate-private utils module with serialization helpers.
  • Documentation for the new HTTP models.

station

  • New Axum HTTP server with handlers for:
    • /backend/adj/DataPackets
    • /backend/adj/OrderPackets
    • /backend/adj/ProtectionPackets
  • Catalogs are serialized once at startup and reused across requests.
  • WebSocket upgrades at /backend, forwarding connections to a channel for future message handling.
  • Configurable bind address, allowed CORS origins, and catalog cache policy.
  • Tests for catalog responses, WebSocket upgrades, and server configuration.
  • Basic server startup in main.rs for manual testing.

@JavierRibaldelRio JavierRibaldelRio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general the module is fine, however there are critical mistakes that must be solved.

May be it is better o include adj/http inside of model instead of adj as you commented in the workshop.

mod info;
mod raw;

#[cfg(feature = "http")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add comment above this line stateing why it is required to use a feature

pub mod http;

#[cfg(feature = "git")]
use std::path::PathBuf;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

idem here (even though it's from a previous module)

@@ -0,0 +1,39 @@
# ADJ HTTP (`adj::http`)

Builds serializable HTTP response bodies from a loaded `Adj`, without modifying

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right now it just only contains the structure of the answer,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add JSON structure, not just refer to example

pub info: AdjInfo,
}

#[cfg(feature = "http")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a way of moving all this logic inside a file inside adj/?

// A remote derive keeps the JSON representation here, without changing model.
#[derive(Serialize)]
#[serde(remote = "ProtectionKind", tag = "type", rename_all = "snake_case")]
enum ProtectionKindDef {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • ProtectionKind sale en snake_case ("not_equal") en /OrderPackets y en PascalCase ("NotEqual") en /ProtectionPackets.

pub struct OrderProtectionResponse {
/// One-based protection position within its measurement, not a packet id.
#[serde(serialize_with = "serialize_adj_id")]
pub id: AdjId,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMPORTANT this is logically wrong ADJId will be always an ADJid not a proteccion

},
"protections": [
{
"id": 1,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WRONG

/// Preserves the entry point used by the test startup code. Upgrade requests
/// to `/backend` receive `503` until [`serve_with_websocket`] is used with a
/// channel connected to the future WebSocket module.
pub async fn serve(listener: TcpListener, adj: &Adj) -> io::Result<()> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No entiendo nada la verdad, has definido una función que te permite configuar y luego no la utilizas, esto marea mucho

serve (http.rs)     ─┐
  └─ serve_with_websocket       ─┤─► router_with_cache(.., Unspecified)   → sin CORS, sin caché
       (server.rs)                                     │
configure_server (configure.rs) ─┘─► router_with_cache(.., config.cache) + CorsLayer

alias: measurement.alias.clone(),
name: measurement.name.clone(),
display_units: measurement.display_units.clone(),
kind: match &measurement.kind {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This match is identical in adj.rs:160-174, dentro de order_response

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants