1
0
mirror of https://github.com/actix/examples synced 2025-04-22 08:34:52 +02:00

feat: fixed endpoints path prefix

This commit is contained in:
Alex Ted 2025-01-21 21:20:22 +03:00
parent 1b14e6e98b
commit e2a957eadd
2 changed files with 10 additions and 10 deletions

View File

@ -38,7 +38,7 @@ cargo run
### Available Routes ### Available Routes
#### `POST /item` #### `POST /items`
Inserts a new item into the PostgreSQL DB. Inserts a new item into the PostgreSQL DB.
@ -63,18 +63,18 @@ On success, a response like the following is returned:
Using [HTTPie]: Using [HTTPie]:
```sh ```sh
http POST localhost:8080/item name=bill http POST localhost:8080/items name=bill
``` ```
Using cURL: Using cURL:
```sh ```sh
curl -S -X POST --header "Content-Type: application/json" --data '{"name":"bill"}' http://localhost:8080/item curl -S -X POST --header "Content-Type: application/json" --data '{"name":"bill"}' http://localhost:8080/items
``` ```
</details> </details>
#### `GET /item/{item_uid}` #### `GET /items/{item_uid}`
Gets an item from the DB using its UID (returned from the insert request or taken from the DB directly). Returns a 404 when no item exists with that UID. Gets an item from the DB using its UID (returned from the insert request or taken from the DB directly). Returns a 404 when no item exists with that UID.
@ -84,13 +84,13 @@ Gets an item from the DB using its UID (returned from the insert request or take
Using [HTTPie]: Using [HTTPie]:
```sh ```sh
http localhost:8080/item/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 http localhost:8080/items/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97
``` ```
Using cURL: Using cURL:
```sh ```sh
curl -S http://localhost:8080/item/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 curl -S http://localhost:8080/items/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97
``` ```
</details> </details>

View File

@ -131,7 +131,7 @@ mod tests {
.await; .await;
// send something that isn't a UUID to `get_item` // send something that isn't a UUID to `get_item`
let req = test::TestRequest::get().uri("/item/123").to_request(); let req = test::TestRequest::get().uri("/items/123").to_request();
let res = test::call_service(&app, req).await; let res = test::call_service(&app, req).await;
assert_eq!(res.status(), StatusCode::NOT_FOUND); assert_eq!(res.status(), StatusCode::NOT_FOUND);
let body = test::read_body(res).await; let body = test::read_body(res).await;
@ -142,7 +142,7 @@ mod tests {
// try to find a non-existent item // try to find a non-existent item
let req = test::TestRequest::get() let req = test::TestRequest::get()
.uri(&format!("/item/{}", Uuid::nil())) .uri(&format!("/items/{}", Uuid::nil()))
.to_request(); .to_request();
let res = test::call_service(&app, req).await; let res = test::call_service(&app, req).await;
assert_eq!(res.status(), StatusCode::NOT_FOUND); assert_eq!(res.status(), StatusCode::NOT_FOUND);
@ -154,7 +154,7 @@ mod tests {
// create new item // create new item
let req = test::TestRequest::post() let req = test::TestRequest::post()
.uri("/item") .uri("/items")
.set_json(models::NewItem::new("Test item")) .set_json(models::NewItem::new("Test item"))
.to_request(); .to_request();
let res: models::Item = test::call_and_read_body_json(&app, req).await; let res: models::Item = test::call_and_read_body_json(&app, req).await;
@ -162,7 +162,7 @@ mod tests {
// get an item // get an item
let req = test::TestRequest::get() let req = test::TestRequest::get()
.uri(&format!("/item/{}", res.id)) .uri(&format!("/items/{}", res.id))
.to_request(); .to_request();
let res: models::Item = test::call_and_read_body_json(&app, req).await; let res: models::Item = test::call_and_read_body_json(&app, req).await;
assert_eq!(res.name, "Test item"); assert_eq!(res.name, "Test item");