Skip to content

not using handlers declared with routing macro should be detectable #2696

@ulf5

Description

@ulf5

Hello,

I've been using actix-web for a while and it's working very well! There is one little thing that's been bothering me, though.
When I write services with actix-web I really like to use the macros for specifying method and path, as in the example below:

use actix_web::{get, web, App, HttpServer, Responder};

#[get("/hello/{name}")]
async fn greet(name: web::Path<String>) -> impl Responder {
    format!("Hello {name}!")
}

#[actix_web::main] // or #[tokio::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().service(greet)
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

I think it's great to have the path and method next to the implementation of the endpoint. However, nearly every time I add a new endpoint I forget to add the service to the app in when setting up the server, leading to a confused developer and a 404 when testing it out :)

I am not experienced enough with Rust's macro system to know if it's actually possible to do, but it would really be great if just using the macro could somehow add the service.

Metadata

Metadata

Assignees

Labels

A-codegenproject: actix-web-codegenC-improvementCategory: an improvement to existing functionalitygood-first-issueeasy to pick up for newcomers

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions