Skip to content

Commit 2980e61

Browse files
authored
Merge pull request #71 from tecladocode/develop
2 parents 56fe5a7 + 8c12eea commit 2980e61

File tree

7 files changed

+3230
-2689
lines changed

7 files changed

+3230
-2689
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from flask import Flask, request
2+
3+
app = Flask(__name__)
4+
5+
stores = [{"name": "My Store", "items": [{"name": "Chair", "price": 15.99}]}]
6+
7+
8+
@app.get("/store")
9+
def get_stores():
10+
return {"stores": stores}
11+
12+
13+
@app.post("/store")
14+
def create_store():
15+
request_data = request.get_json()
16+
new_store = {"name": request_data["name"], "items": []}
17+
stores.append(new_store)
18+
return new_store, 201
19+
20+
21+
@app.post("/store/<string:name>/item")
22+
def create_item(name):
23+
request_data = request.get_json()
24+
for store in stores:
25+
if store["name"] == name:
26+
new_item = {"name": request_data["name"], "price": request_data["price"]}
27+
store["items"].append(new_item)
28+
return new_item, 201
29+
return {"message": "Store not found"}, 404
30+
31+
32+
@app.get("/store/<string:name>")
33+
def get_store(name):
34+
for store in stores:
35+
if store["name"] == name:
36+
return store
37+
return {"message": "Store not found"}, 404
38+
39+
40+
@app.get("/store/<string:name>/item")
41+
def get_item_in_store(name):
42+
for store in stores:
43+
if store["name"] == name:
44+
return {"items": store["items"]}
45+
return {"message": "Store not found"}, 404

docs/docs/04_docker_intro/03_run_docker_container/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Docker Desktop is an application to help you manage your images and containers.
66

77
## Create your Docker image
88

9-
Next, download the REST API code from Section 3. You can download it here: LINK.
9+
Next, download the REST API code from Section 3. You can download it [here](https://www.dropbox.com/s/qs28amk2h420f2y/s03-final-code.zip?dl=0).
1010

1111
If you want to use the code you wrote while following the videos, that's fine! Just make sure it works by running the Flask app locally and testing it with Insomnia REST Client or Postman.
1212

docs/docs/05_flask_smorest/05_reload_api_docker_container/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ To do so, stop the running container (if you have one running), and use this com
7878
docker run -dp 5000:5000 -w /app -v "$(pwd):/app" flask-smorest-api
7979
```
8080

81+
:::info Windows command
82+
The command on Windows is the same, but the paths have to be passed in differently:
83+
84+
```
85+
docker run -dp 5000:5000 -w /app -v "/c/Documents/yourproject:/app" flask-smorest-api
86+
```
87+
88+
Instead of `/c/Documents/yourproject`, use the path to your project (but remember to use `/c/` instead of `C:/`).
89+
:::
90+
8191
- `-dp 5000:5000` - same as before. Run in detached (background) mode and create a port mapping.
8292
- `-w /app` - sets the container's present working directory where the command will run from.
8393
- `-v "$(pwd):/app"` - bind mount (link) the host's present directory to the container's `/app` directory. Note: Docker requires absolute paths for binding mounts, so in this example we use `pwd` for printing the absolute path of the working directory instead of typing it manually.

docs/docusaurus.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ const darkCodeTheme = require("prism-react-renderer/themes/dracula");
77
/** @type {import('@docusaurus/types').Config} */
88
const config = {
99
title: "REST APIs with Flask and Python",
10-
tagline:
11-
"Build and deploy REST APIs using Flask, PostgreSQL, Docker, and Celery",
12-
url: "https://rest-apis.teclado.com",
10+
tagline: "Build and deploy REST APIs using Flask, PostgreSQL, and Docker",
11+
url: "https://rest-apis-flask.teclado.com",
1312
baseUrl: "/",
1413
onBrokenLinks: "throw",
1514
onBrokenMarkdownLinks: "warn",
@@ -40,7 +39,7 @@ const config = {
4039
}),
4140
],
4241
],
43-
42+
plugins: [require.resolve("@cmfcmf/docusaurus-search-local")],
4443
themeConfig:
4544
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
4645
({

0 commit comments

Comments
 (0)