Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
httpd: Add apiVersion to root handler and node information
Merged did:key:z6MkkfM3...sVz5 opened 2 years ago

This will help consumers of the httpd to check if they are on the right version of the API

3 files changed +8 -5 d04d9d7d 5ffbf754
modified radicle-httpd/src/api.rs
@@ -34,7 +34,9 @@ use crate::api::error::Error;
use crate::cache::Cache;
use crate::Options;

-
pub const VERSION: &str = env!("RADICLE_VERSION");
+
pub const RADICLE_VERSION: &str = env!("RADICLE_VERSION");
+
// This version has to be updated on every breaking change to the radicle-httpd API.
+
pub const API_VERSION: &str = "0.1.0";

/// Identifier for sessions
type SessionId = String;
modified radicle-httpd/src/api/v1.rs
@@ -11,7 +11,7 @@ use axum::routing::get;
use axum::Router;
use serde_json::json;

-
use crate::api::{Context, VERSION};
+
use crate::api::{Context, API_VERSION, RADICLE_VERSION};

pub fn router(ctx: Context) -> Router {
    let root_router = Router::new()
@@ -34,7 +34,8 @@ async fn root_handler(State(ctx): State<Context>) -> impl IntoResponse {
    let response = json!({
        "message": "Welcome!",
        "service": "radicle-httpd",
-
        "version": format!("{}-{}", VERSION, env!("GIT_HEAD")),
+
        "version": format!("{}-{}", RADICLE_VERSION, env!("GIT_HEAD")),
+
        "apiVersion": API_VERSION,
        "nid": ctx.profile.public_key,
        "path": "/api/v1",
        "links": [
modified radicle-httpd/src/api/v1/node.rs
@@ -12,7 +12,7 @@ use radicle::node::{policy, AliasStore, Handle, NodeId, DEFAULT_TIMEOUT};
use radicle::Node;

use crate::api::error::Error;
-
use crate::api::{self, Context, PoliciesQuery, VERSION};
+
use crate::api::{self, Context, PoliciesQuery, RADICLE_VERSION};
use crate::axum_extra::{Path, Query};

pub fn router(ctx: Context) -> Router {
@@ -47,7 +47,7 @@ async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {
    };
    let response = json!({
        "id": node_id.to_string(),
-
        "version": format!("{}-{}", VERSION, env!("GIT_HEAD")),
+
        "version": format!("{}-{}", RADICLE_VERSION, env!("GIT_HEAD")),
        "config": config,
        "state": node_state,
    });