diff --git a/modules/module-test-cpp/CMakeLists.txt b/modules/module-test-cpp/CMakeLists.txt index f1731454b41..ae5c37ca153 100644 --- a/modules/module-test-cpp/CMakeLists.txt +++ b/modules/module-test-cpp/CMakeLists.txt @@ -41,7 +41,7 @@ target_link_libraries(${OUTPUT_NAME} PRIVATE spacetimedb_cpp_library) # Emscripten specific settings if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # Export list as a single variable (no extra quoting per-platform) - set(EXPORTED_FUNCS "['_malloc','_free','___describe_module__','___call_reducer__','___call_procedure__','___call_view__','___call_view_anon__']") + set(EXPORTED_FUNCS "['_malloc','_free','___describe_module__','___call_reducer__','___call_procedure__','___call_view__','___call_view_anon__','___call_http_handler__']") # Produce a standalone .wasm (no JS harness) with no entry point target_link_options(lib PRIVATE @@ -67,4 +67,4 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # Name the output lib.wasm set_target_properties(lib PROPERTIES OUTPUT_NAME "lib" SUFFIX ".wasm") -endif() \ No newline at end of file +endif() diff --git a/modules/module-test-cpp/src/lib.cpp b/modules/module-test-cpp/src/lib.cpp index 49f413e3a27..3a93f0b20ec 100644 --- a/modules/module-test-cpp/src/lib.cpp +++ b/modules/module-test-cpp/src/lib.cpp @@ -707,3 +707,16 @@ SPACETIMEDB_PROCEDURE(std::string, get_my_schema_via_http, ProcedureContext ctx) return result.error(); } } + +SPACETIMEDB_HTTP_HANDLER(get_simple, HandlerContext ctx, HttpRequest request) { + return HttpResponse{ + 200, + HttpVersion::Http11, + {}, + HttpBody::from_string("ok"), + }; +} + +SPACETIMEDB_HTTP_ROUTER(router) { + return Router().get("/get", get_simple); +} diff --git a/modules/module-test-cs/Lib.cs b/modules/module-test-cs/Lib.cs index 7ac37fc3dcb..b8da8338ce2 100644 --- a/modules/module-test-cs/Lib.cs +++ b/modules/module-test-cs/Lib.cs @@ -1,5 +1,6 @@ namespace SpacetimeDB.Modules.ModuleTestCs; +using System.Collections.Generic; using System.Reflection.Metadata.Ecma335; using SpacetimeDB; @@ -502,4 +503,19 @@ public static void assert_caller_identity_is_module_identity(ReducerContext ctx) Log.Info($"Called by the owner {owner}"); } } + + [SpacetimeDB.HttpHandler] + public static HttpResponse get_simple(HandlerContext ctx, HttpRequest request) + { + return new HttpResponse( + 200, + HttpVersion.Http11, + new List(), + HttpBody.FromString("ok") + ); + } + + [SpacetimeDB.HttpRouter] + public static Router router() => + SpacetimeDB.Router.New().Get("/get", Handlers.get_simple); } diff --git a/modules/module-test-ts/src/index.ts b/modules/module-test-ts/src/index.ts index b8f0c01d558..8a4f973f5e5 100644 --- a/modules/module-test-ts/src/index.ts +++ b/modules/module-test-ts/src/index.ts @@ -3,7 +3,9 @@ // ───────────────────────────────────────────────────────────────────────────── import { ScheduleAt } from 'spacetimedb'; import { + Router, schema, + SyncResponse, table, t, type Infer, @@ -520,3 +522,11 @@ export const getMySchemaViaHttp = spacetimedb.procedure(t.string(), ctx => { throw e; } }); + +export const get_simple = spacetimedb.httpHandler( + (_ctx, _req) => new SyncResponse('ok') +); + +export const router = spacetimedb.httpRouter( + new Router().get('/get', get_simple) +); diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index 56e6b288e2d..c51563a59c6 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -1,6 +1,7 @@ #![allow(clippy::disallowed_names)] use std::time::Duration; +use spacetimedb::http::{Body, HandlerContext, Request, Response, Router}; use spacetimedb::spacetimedb_lib::db::raw_def::v9::TableAccess; use spacetimedb::spacetimedb_lib::{self, bsatn}; use spacetimedb::{ @@ -552,5 +553,15 @@ fn get_my_schema_via_http(ctx: &mut ProcedureContext) -> String { } } +#[spacetimedb::http::handler] +fn get_simple(_ctx: &mut HandlerContext, _req: Request) -> Response { + Response::new(Body::from_bytes("ok")) +} + +#[spacetimedb::http::router] +fn router() -> Router { + Router::new().get("/get", get_simple) +} + #[spacetimedb::settings] const CASE_CONVERSION_POLICY: CaseConversionPolicy = CaseConversionPolicy::SnakeCase;