Skip to content

Commit

Permalink
feat: fixed endpoints path prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexted committed Jan 21, 2025
1 parent 7f2ee70 commit 4802c38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions databases/diesel-async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cargo run

### Available Routes

#### `POST /item`
#### `POST /items`

Inserts a new item into the PostgreSQL DB.

Expand All @@ -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
```

</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.

Expand All @@ -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
```

</details>
Expand Down
8 changes: 4 additions & 4 deletions databases/diesel-async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -154,15 +154,15 @@ 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;
assert_eq!(res.name, "Test item");

// 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");
Expand Down

0 comments on commit 4802c38

Please sign in to comment.