httpd: Add apiVersion to root handler and node information

This will help consumers of the httpd to check if they are on the right
version of the API
This commit is contained in:
Sebastian Martinez 2024-04-29 15:57:33 +02:00 committed by cloudhead
parent d04d9d7d1f
commit 5ffbf7545f
No known key found for this signature in database
3 changed files with 8 additions and 5 deletions

View File

@ -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;

View File

@ -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": [

View File

@ -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,
});