Skip to content

fix(api): align api names and serialisation#1029

Merged
JesseTheRobot merged 12 commits into
masterfrom
jason/rationalise-api
Dec 4, 2025
Merged

fix(api): align api names and serialisation#1029
JesseTheRobot merged 12 commits into
masterfrom
jason/rationalise-api

Conversation

@glottologist

@glottologist glottologist commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

Describe the changes
Aligns Public API routes to use canonical formatting (e.g /chunk/data_root -> /chunk/data-root) (private/gossip API is untouched)
Additionally changes struct serialisation to be "canonical" - camelCase formatting, numeric types >=u64 are serialized as strings (due to JS numeric constraints), and changes all use of plain text responses (errors or success) to use JSON instead so we can easily extend them in the future.

NOTE: there is a large custom serializer in types/canonical.rs that is used to serialize the ConsensusConfig using the rules outlined above. it's only used there as we also deserialize this structure from the config toml, and attributes to change it to use camelCase will cause snake_case toml entries to fail.

Related Issue(s)
Please link to the issue(s) that will be closed with this PR.

Checklist

  • Tests have been added/updated for the changes.
  • Documentation has been updated for the changes (if applicable).
  • The code follows Rust's style guidelines.

Additional Context
Add any other context about the pull request here.

@glottologist glottologist marked this pull request as ready for review November 26, 2025 10:02
Adds a custom "canonical JSON" ser/des for use in our API
The reason we need this is enforcing correct formatting with #[serde(with ...)] and #[serde(rename_all = "camelCase")] was error prone and oftentimes required duplicate structures to prevent these attributes from interfereing with other ser/des targets (i.e the toml config)
NOTE: claude produced this version of the code, I still need to more thoroughly review it.
@JesseTheRobot JesseTheRobot merged commit 5967d27 into master Dec 4, 2025
17 checks passed
@JesseTheRobot JesseTheRobot deleted the jason/rationalise-api branch December 4, 2025 17:49
JesseTheRobot added a commit that referenced this pull request Dec 10, 2025
* fix(api): align api names and serialisation

* feat: custom serde serializer/deserializer impl

Adds a custom "canonical JSON" ser/des for use in our API
The reason we need this is enforcing correct formatting with #[serde(with ...)] and #[serde(rename_all = "camelCase")] was error prone and oftentimes required duplicate structures to prevent these attributes from interfereing with other ser/des targets (i.e the toml config)
NOTE: claude produced this version of the code, I still need to more thoroughly review it.

* feat: add custom ApiErrors, convert block_index_route

* wip: fixes

* wip: tweaks

* wip: fixes

* feat: add Canonical serialization wrapper for `/network/config`

* chore: dead code cleanup

* chore: add doc comment to canonical

---------

Co-authored-by: JesseTheRobot <jesse.cruz.wright@gmail.com>
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.

2 participants