Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/client-api/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod internal;
pub mod metrics;
pub mod prometheus;
pub mod subscribe;
pub mod unstable;

/// This API call is just designed to allow clients to determine whether or not they can
/// establish a connection to SpacetimeDB. This API call doesn't actually do anything.
Expand Down Expand Up @@ -40,4 +41,5 @@ where
axum::Router::new()
.nest("/v1", router.layer(cors))
.nest("/internal", internal::router())
.nest("/unstable", unstable::router())
}
21 changes: 21 additions & 0 deletions crates/client-api/src/routes/unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use axum::response::IntoResponse;
use spacetimedb_lib::{sats, Timestamp};

use crate::NodeDelegate;

/// Returns the database's view of the current time,
/// as a SATS-JSON encoded [`Timestamp`].
async fn get_timestamp() -> impl IntoResponse {
axum::Json(sats::serde::SerdeWrapper(Timestamp::now())).into_response()
}

/// The internal router is for routes which are early in design,
/// and may incompatibly change or be removed without a major version bump.
pub fn router<S>() -> axum::Router<S>
where
S: NodeDelegate + Clone + 'static,
{
use axum::routing::get;

axum::Router::new().route("/timestamp", get(get_timestamp))
}
5 changes: 3 additions & 2 deletions smoketests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ def api_call(self, method, path, body = None, headers = {}):
log_cmd([method, path])
conn.request(method, path, body, headers)
resp = conn.getresponse()
logging.debug(f"{resp.status} {resp.read()}")
body = resp.read()
logging.debug(f"{resp.status} {body}")
if resp.status != 200:
raise resp
resp
return body


@classmethod
Expand Down
19 changes: 19 additions & 0 deletions smoketests/tests/timestamp_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .. import Smoketest, random_string
import unittest
import json
import io

TIMESTAMP_TAG = "__timestamp_micros_since_unix_epoch__"

class TimestampRoute(Smoketest):
AUTOPUBLISH = False

def test_timestamp_route(self):
resp = self.api_call(
"GET",
"/unstable/timestamp",
)
timestamp = json.load(io.BytesIO(resp))
self.assertIsInstance(timestamp, dict)
self.assertIn(TIMESTAMP_TAG, timestamp)
self.assertIsInstance(timestamp[TIMESTAMP_TAG], int)
Loading