feat: echo post api endpoint

This endpoint responds with the body that was sent with the
post request
main
Carsten Kragelund 2023-07-28 17:33:43 +02:00
parent 2a71ade56f
commit 76ec0ce0f4
Signed by: nyx
GPG Key ID: CADDADEEC9F753C0
3 changed files with 29 additions and 1 deletions

@ -7,11 +7,16 @@ const bolt = createBoltClient<Handlers, typeof routes>(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 (
<main>
<Welcome>
<p className="mt-4">{title}</p>
<span>The server replied: {message}</span>
</Welcome>
</main>
);

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

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