Chihwei
Chihwei
CDCloudflare Developers
Created by Chihwei on 6/18/2024 in #workers-help
worker-rs: http hello world
use worker::*;

#[event(fetch)]
async fn fetch(
_req: HttpRequest,
_env: Env,
_ctx: Context,
) -> Result<HttpResponse> {
console_error_panic_hook::set_once();
Ok(http::Response::builder()
.status(http::StatusCode::OK)
.body(Body::empty())?)
}
use worker::*;

#[event(fetch)]
async fn fetch(
_req: HttpRequest,
_env: Env,
_ctx: Context,
) -> Result<HttpResponse> {
console_error_panic_hook::set_once();
Ok(http::Response::builder()
.status(http::StatusCode::OK)
.body(Body::empty())?)
}
How can I put a simple string into the body? Tried many ways but didn't work. The body seems to be only accepting a stream. (http feature flag enabled for worker-rs)
3 replies