From e2a957eadd9f48f2c9fac0771ef8eb025dc4ffaf Mon Sep 17 00:00:00 2001 From: Alex Ted Date: Tue, 21 Jan 2025 21:20:22 +0300 Subject: [PATCH] feat: fixed endpoints path prefix --- databases/diesel-async/README.md | 12 ++++++------ databases/diesel-async/src/main.rs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/databases/diesel-async/README.md b/databases/diesel-async/README.md index 983beede..d773cf9f 100644 --- a/databases/diesel-async/README.md +++ b/databases/diesel-async/README.md @@ -38,7 +38,7 @@ cargo run ### Available Routes -#### `POST /item` +#### `POST /items` Inserts a new item into the PostgreSQL DB. @@ -63,18 +63,18 @@ On success, a response like the following is returned: Using [HTTPie]: ```sh -http POST localhost:8080/item name=bill +http POST localhost:8080/items name=bill ``` Using cURL: ```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 ``` -#### `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. @@ -84,13 +84,13 @@ Gets an item from the DB using its UID (returned from the insert request or take Using [HTTPie]: ```sh -http localhost:8080/item/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 +http localhost:8080/items/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 ``` Using cURL: ```sh -curl -S http://localhost:8080/item/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 +curl -S http://localhost:8080/items/9e46baba-a001-4bb3-b4cf-4b3e5bab5e97 ``` diff --git a/databases/diesel-async/src/main.rs b/databases/diesel-async/src/main.rs index b6cb829f..cc64f54d 100644 --- a/databases/diesel-async/src/main.rs +++ b/databases/diesel-async/src/main.rs @@ -131,7 +131,7 @@ mod tests { .await; // 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; assert_eq!(res.status(), StatusCode::NOT_FOUND); let body = test::read_body(res).await; @@ -142,7 +142,7 @@ mod tests { // try to find a non-existent item let req = test::TestRequest::get() - .uri(&format!("/item/{}", Uuid::nil())) + .uri(&format!("/items/{}", Uuid::nil())) .to_request(); let res = test::call_service(&app, req).await; assert_eq!(res.status(), StatusCode::NOT_FOUND); @@ -154,7 +154,7 @@ mod tests { // create new item let req = test::TestRequest::post() - .uri("/item") + .uri("/items") .set_json(models::NewItem::new("Test item")) .to_request(); let res: models::Item = test::call_and_read_body_json(&app, req).await; @@ -162,7 +162,7 @@ mod tests { // get an item let req = test::TestRequest::get() - .uri(&format!("/item/{}", res.id)) + .uri(&format!("/items/{}", res.id)) .to_request(); let res: models::Item = test::call_and_read_body_json(&app, req).await; assert_eq!(res.name, "Test item");