Skip to content

Commit

Permalink
docs: fix #908
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Oct 23, 2024
1 parent ace9114 commit fa84d60
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,34 @@ injected: "tests/requests/mod.rs"
This is the generated controller body:

```rust
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::unnecessary_struct_initialization)]
#![allow(clippy::unused_async)]
use loco_rs::prelude::*;
use axum::debug_handler;

pub async fn echo(req_body: String) -> String {
req_body
}

pub async fn hello(State(_ctx): State<AppContext>) -> Result<Response> {
// do something with context (database, etc)
format::text("hello")
#[debug_handler]
pub async fn index(State(_ctx): State<AppContext>) -> Result<Response> {
format::empty()
}

pub fn routes() -> Routes {
Routes::new()
.prefix("guide")
.add("/", get(hello))
.add("/echo", post(echo))
.prefix("guides/")
.add("/", get(index))
}
```


Change the `index` handler body:

```rust
// replace
format::empty()
// with this
format::text("hello")
```

Start the server:

<!-- <snip id="starting-the-server-command" inject_from="yaml" template="sh"> -->
Expand All @@ -181,7 +189,7 @@ cargo loco start
Now, let's test it out:

```sh
$ curl localhost:5150/guide
$ curl localhost:5150/guides
hello
```

Expand Down

0 comments on commit fa84d60

Please sign in to comment.