0

I have a function, with the signature:

async fn index(bearer_control: web::Json<BearerControl>) -> Result<String> {

It is used an a web server:

HttpServer::new(|| App::new().route("/", web::post().to(index)))
    .bind_openssl("127.0.0.1:1618", builder)?
    .run()
    .await

I want to return a 204 No Content.

I've tried returning an empty string, but that is still a 200 OK.

What sort of function return type do I need from index() and how do I attach a function with a different return type to the server?

fadedbee
  • 42,671
  • 44
  • 178
  • 308

1 Answers1

2

Actix-web expects your handlers to return something that can be converted to an HttpResponse, which of course includes HttpResponse itself:

async fn index(bearer_control: web::Json<BearerControl>) -> impl Responder {
    HttpResponse::new (StatusCode::NO_CONTENT)
}
Jmb
  • 18,893
  • 2
  • 28
  • 55