Answer /greeting from a handler

Register a closure in web.rs, move it into src/http/handlers, and find the file again with route:list.

The beta still applies: a route signature you copy today can change before 1.0. The routing guide is the contract for this lesson.

When a request arrives, Laravel matches its method and URI to a route. The smallest route is a closure. In src/routes/web.rs, inside the existing routes function, add:

use laravel::prelude::*;

pub fn routes(route: &mut Router) {
    route.get("/greeting", async || "Hello from Field Notes");
}

Keep the routes the starter already registered. web routes run in the web middleware group: sessions, encrypted cookies, and CSRF protection. You do not add that group yourself for a route in this file.

laravel dev rebuilds when the Rust file changes. Open http://127.0.0.1:8000/greeting. If the compiler stops the rebuild, read the error before refreshing. The CLI hides compiler output when the build succeeds.

Move the page into a handler

A route file full of closures gets hard to read. The routing guide’s next step is a handler: an async function under src/http/handlers. Create src/http/handlers/greeting.rs:

use laravel::prelude::*;

pub async fn show() -> &'static str {
    "Hello from Field Notes"
}

Declare the module the same way the other handler modules are declared in src/http/handlers/mod.rs. If those lines are pub mod, yours should be too:

pub mod greeting;

Point the route at the function. The route file stays a list of URIs:

use crate::http::handlers::greeting;

pub fn routes(route: &mut Router) {
    route.get("/greeting", greeting::show);
}

The handler’s arguments are extractors. This one needs nothing from the request, so the parameter list is empty. Later lessons will add a User, a Valid<StoreNote>, and Auth<User> in that position. The function’s return value is the response. A string is enough for this page.

See the route, and the rest of the tree

From the app directory:

laravel route:list

-v includes middleware. --path=greeting keeps the list to this URI. --json prints JSON. --handler=greeting filters by handler.

The directory-structure guide is the map for everything you will add:

Path What you put there in this series
src/routes/web.rs Browser routes, with session and CSRF
src/routes/api.rs Stateless routes, prefixed with /api
src/http/handlers/ One module per resource
src/models/ The starter User, then Note
database/migrations/ Schema changes, compiled into the binary
resources/js/pages/ Inertia components, such as Notes/Index.tsx
resources/views/ Jinja templates, including mail
tests/ #[laravel::test] functions
src/app.rs Routing, the auth guard, and migrations!

src/lib.rs declares modules. Rust compiles only modules you declare. If a new jobs or policies directory never gets a mod line, the attribute macros inside it never run, and the compiler does not warn you. The structure guide shows the shape: pub mod jobs; in src/lib.rs, then mod process_note; inside src/jobs/mod.rs.

Cargo’s output lives in target/, frontend dependencies in node_modules/, built assets in public/build/, and secrets in .env. Git already ignores those. Do not commit them to make a lesson “easier to share.”

Check your work

Change the greeting string, rebuild through laravel dev, and confirm /greeting shows the new text.

Back to roadmap