-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Endpoints for get store by name and get items in store by name
- Loading branch information
1 parent
e04c523
commit ce1c5fc
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions
32
Section_3_Your_first_REST_API/Lec_60_How_to_get_a_specific_store_and_its_items.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# How to get a specific store and its items | ||
|
||
Picking up from last lecture | ||
|
||
Make endpoints for getting store by name and getting items in the store by name. | ||
|
||
```py | ||
@app.get("/store/<string:name>") | ||
def get_store(name): | ||
for store in stores: | ||
if store["name"] == name: | ||
return store | ||
return {"message": "Store not found"}, 404 | ||
|
||
|
||
@app.get("/store/<string:name>/item") | ||
def get_item_in_store(name): | ||
for store in stores: | ||
if store["name"] == name: | ||
return {"items": store["items"]} # Dict for extensibility later, more keys doesn't hurt anything unlike changing data type | ||
return {"message": "Store not found"}, 404 | ||
``` | ||
|
||
Test get store by name: | ||
|
||
 | ||
|
||
Test get store items by name: | ||
|
||
 | ||
|
||
Automated tests on everything we run. GitHub has some auto-tests for view and using. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters