Skip to content

Commit

Permalink
First endpoint. Fix some images
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonWelch committed Sep 25, 2023
1 parent 51d7d2d commit f8f179b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
Binary file added Screenshots/55_store_return.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ code.py: __main__

Notice on run that the imports are all reverse. The deepest file runs first.

File Structure

![30_file_org image](https://github.com/HarrisonWelch/REST-APIs-with-Flask-and-Python-in-2023-Notes/blob/master/Screenshots/30_file_org.png)

## Relative input

Put a function in mymodule.py
Expand Down Expand Up @@ -72,4 +76,4 @@ If you are to use relative imports you need to the keep the same file at the top

`import *` will import everything.

Advice don't use relative import. Brain hurt.
Advice - don't use relative import. Brain hurt.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Lec_55_Your_first_REST_API_endpoint.md

Picking up from last lecture

```py
from flask import Flask

app = Flask(__name__) # Creates flask app that does a lot for us
```

Going to put the data in a python list, DB later.

```py
from flask import Flask

app = Flask(__name__) # Creates flask app that does a lot for us

stores = [
{
"name": "My Store",
"items": [
{
"name": "Chair",
"price": 15.99
}
]
}
]

@app.get("/store") # Endpoint. http://127.0.0.1:5000/store
def get_stores():
return {"stores": stores}

```

Returns:

![55_store_return image](https://github.com/HarrisonWelch/REST-APIs-with-Flask-and-Python-in-2023-Notes/blob/master/Screenshots/55_store_return.png)

Spaces and tabs don't matter in JSON. Order does not matter in JSON.

We'll talk about what JSON is in the next lecture.

17 changes: 17 additions & 0 deletions Section_3_Your_first_REST_API/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
from flask import Flask

app = Flask(__name__) # Creates flask app that does a lot for us

stores = [
{
"name": "My Store",
"items": [
{
"name": "Chair",
"price": 15.99
}
]
}
]


@app.get("/store") # Endpoint. http://127.0.0.1:5000/store
def get_stores():
return {"stores": stores}

0 comments on commit f8f179b

Please sign in to comment.