Skip to content

Commit

Permalink
Flask setup
Browse files Browse the repository at this point in the history
  • Loading branch information
HarrisonWelch committed Sep 25, 2023
1 parent bd7fcae commit 51d7d2d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/__pycache__/
**/*.pyc
**/*.pyc
**/.venv
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Overview of the project we'll build

Building our first API. Receive requests from mobile app and respond with some data. Benefit is that multiple sources can request and receive.
* Create stores
* Create items within a store
* Get list of all items
* Given its name, retrieve an individual store and all its items.
* Given a store name, get only a list of items within it.

- Create stores
- Create items within a store
- Get list of all items
- Given its name, retrieve an individual store and all its items.
- Given a store name, get only a list of items within it.

## Create stores

Expand All @@ -18,7 +19,7 @@ POST /store {"name": "My Store"}
### Response

```json
{"name": "My store", "items": []}
{ "name": "My store", "items": [] }
```

## Create Items
Expand All @@ -32,7 +33,7 @@ POST /store/My Store/item {"name": "Chair", "price": 175.50}
### Response

```json
{"name": "Chair", "price": 175.50}
{ "name": "Chair", "price": 175.5 }
```

May not be important, but this will confirm. Respond with information sent.
Expand All @@ -49,17 +50,17 @@ GET /store

```json
{
"stores": [
"stores": [
{
"name": "My Store",
"items": [
{
"name": "My Store",
"items": [
{
"name": "Chair",
"price": 175.50
}
]
"name": "Chair",
"price": 175.5
}
]
]
}
]
}
```

Expand All @@ -75,23 +76,31 @@ GET /store/My Store

```json
{
"name": "My Store",
"items": [
{
"name": "Chair",
"price": 175.50
}
]
"name": "My Store",
"items": [
{
"name": "Chair",
"price": 175.5
}
]
}
```

## Get a particular store
## Get only items in a store

### Request

```
GET /store/My Store
GET /store/My Store/item
```

### Response

```json
[
{
"name": "Chair",
"price": 175.50
}
]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Initial set-up for a Flask app

python -m venv .venv

In terminal run <path-to-venv>/Scripts/activate.bat

Then your terminal will have `(.venv)` in front to signify its working

```
(.venv) C:\...\REST_APIs_with_Flask_and_Python_in_2023\Section_3_Your_first_REST_API\.venv\Scripts>
```

Then run `pip install flask` in the virtual env. Lib/site-packages should have stuff in it.

```py
from flask import Flask

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

Filname and variable must be app.

Now run with `flask run`

```sh
>flask run
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
```

Running IP is in the logs above. We will be able to intercept that data and do something with it.

`Ctrl+c` to stop

Now we are ready to make an endpoint.
3 changes: 3 additions & 0 deletions Section_3_Your_first_REST_API/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from flask import Flask

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

0 comments on commit 51d7d2d

Please sign in to comment.