diff --git a/app/page.tsx b/app/page.tsx index a0994f6..612fb99 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,11 +7,16 @@ const bolt = createBoltClient(routes, { export default async function Home() { const { data: title } = await bolt("hello").get(routes.hello); + const { data: message } = await bolt("echo").post( + routes.echo, + "Hello from the client!" + ); return (

{title}

+ The server replied: {message}
); diff --git a/pages/api/bindings.ts b/pages/api/bindings.ts index 80094b0..d2dc866 100644 --- a/pages/api/bindings.ts +++ b/pages/api/bindings.ts @@ -14,7 +14,13 @@ export interface Handlers { isDynamic: false }, }, - mutations: {}, + mutations: { + "echo": { + output: string + type: 'post' + isDynamic: false + } + }, } export const routes = { @@ -26,4 +32,8 @@ export const routes = { url: '/hello', type: 'query', }, + "echo": { + url: '/echo', + type: 'post', + }, } as const \ No newline at end of file diff --git a/pages/api/routes/echo.rs b/pages/api/routes/echo.rs new file mode 100644 index 0000000..b543b11 --- /dev/null +++ b/pages/api/routes/echo.rs @@ -0,0 +1,13 @@ +use rapid_web::actix::web::Bytes; +use rapid_web::actix::HttpResponse; +use rapid_web::rapid_web_codegen::rapid_handler; + +pub const ROUTE_KEY: &str = "echo"; +pub type RapidOutput = String; + +#[rapid_handler] +pub async fn post(bytes: Bytes) -> HttpResponse { + let body = String::from_utf8(bytes.to_vec()).unwrap(); + println!("Body: {}", &body); + HttpResponse::Ok().body(body) +}