Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: updates and adds to examples folder. #64

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions examples/00_quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Go to [http://127.0.0.1:5000/apidocs/](http://127.0.0.1:5000/apidocs/) in a brow

### Create a ToDo item
```
curl -X POST --location "http://127.0.0.1:5000/todos" \
curl -X POST --location "http://127.0.0.1:5000/todos/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"take out garbage again\"
Expand All @@ -32,44 +32,44 @@ curl -X POST --location "http://127.0.0.1:5000/todos" \

### List all ToDo items (flat)
```
curl -X GET --location "http://127.0.0.1:5000/todos" \
curl -X GET --location "http://127.0.0.1:5000/todos/" \
-d "Accept: application/json"
```

### List all ToDo items (paginated)
```
curl -X GET --location "http://127.0.0.1:5000/todos?limit=2&offset=1" \
curl -X GET --location "http://127.0.0.1:5000/todos/?limit=2&offset=1" \
-d "Accept: application/json"
```

### Search ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/todos?search=garbage" \
curl -X GET --location "http://127.0.0.1:5000/todos/?search=garbage" \
-d "Accept: application/json"
```

### Filter ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/todos?filters=%7B%22text%22%3A+%22take+out+garbage+again%22%7D" \
curl -X GET --location "http://127.0.0.1:5000/todos/?filters=%7B%22text%22%3A+%22take+out+garbage+again%22%7D" \
-d "Accept: application/json"
```
_querystring urldecodes to `filters={"text": "take out garbage again"}`_

### Sort ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/todos?sort=text" \
curl -X GET --location "http://127.0.0.1:5000/todos/?sort=text" \
-d "Accept: application/json"
```

### Fetch ToDo item
```
curl -X GET --location "http://127.0.0.1:5000/todos/1" \
curl -X GET --location "http://127.0.0.1:5000/todos/1/" \
-d "Accept: application/json"
```

### Update ToDo item
```
curl -X PUT --location "http://127.0.0.1:5000/todos/1" \
curl -X PUT --location "http://127.0.0.1:5000/todos/1/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"Updated todo item\"
Expand All @@ -78,7 +78,7 @@ curl -X PUT --location "http://127.0.0.1:5000/todos/1" \

### Patch ToDo item
```
curl -X PATCH --location "http://127.0.0.1:5000/todos/1" \
curl -X PATCH --location "http://127.0.0.1:5000/todos/1/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"Updated todo item\"
Expand All @@ -87,7 +87,5 @@ curl -X PATCH --location "http://127.0.0.1:5000/todos/1" \

### Delete ToDo Item
```
curl -X DELETE --location "http://127.0.0.1:5000/todos/1"
curl -X DELETE --location "http://127.0.0.1:5000/todos/1/"
```


4 changes: 4 additions & 0 deletions examples/01_authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ curl to store/use cookies in order to test authenticated requests.

`pipenv run python3 app.py`

## Swagger UI

Go to [http://127.0.0.1:5000/apidocs/](http://127.0.0.1:5000/apidocs/) in a browser.

## CURL Commands

### Login
Expand Down
26 changes: 14 additions & 12 deletions examples/02_pydantic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ generated by Flask-Muck.

`pipenv run python3 app.py`

## Swagger UI

Go to [http://127.0.0.1:5000/apidocs/](http://127.0.0.1:5000/apidocs/) in a browser.

## CURL Commands

### Create a ToDo item
```
curl -X POST --location "http://127.0.0.1:5000/api/v1/todos" \
curl -X POST --location "http://127.0.0.1:5000/todos/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"take out garbage again\"
Expand All @@ -27,44 +31,44 @@ curl -X POST --location "http://127.0.0.1:5000/api/v1/todos" \

### List all ToDo items (flat)
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos" \
curl -X GET --location "http://127.0.0.1:5000/todos/" \
-d "Accept: application/json"
```

### List all ToDo items (paginated)
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos?limit=2&offset=1" \
curl -X GET --location "http://127.0.0.1:5000/todos/?limit=2&offset=1" \
-d "Accept: application/json"
```

### Search ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos?search=garbage" \
curl -X GET --location "http://127.0.0.1:5000/todos/?search=garbage" \
-d "Accept: application/json"
```

### Filter ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos?filters=%7B%22text%22%3A+%22take+out+garbage+again%22%7D" \
curl -X GET --location "http://127.0.0.1:5000/todos/?filters=%7B%22text%22%3A+%22take+out+garbage+again%22%7D" \
-d "Accept: application/json"
```
_querystring urldecodes to `filters={"text": "take out garbage again"}`_

### Sort ToDo items
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos?sort=text" \
curl -X GET --location "http://127.0.0.1:5000/todos/?sort=text" \
-d "Accept: application/json"
```

### Fetch ToDo item
```
curl -X GET --location "http://127.0.0.1:5000/api/v1/todos/1" \
curl -X GET --location "http://127.0.0.1:5000/todos/1/" \
-d "Accept: application/json"
```

### Update ToDo item
```
curl -X PUT --location "http://127.0.0.1:5000/api/v1/todos/1" \
curl -X PUT --location "http://127.0.0.1:5000/todos/1/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"Updated todo item\"
Expand All @@ -73,7 +77,7 @@ curl -X PUT --location "http://127.0.0.1:5000/api/v1/todos/1" \

### Patch ToDo item
```
curl -X PATCH --location "http://127.0.0.1:5000/api/v1/todos/1" \
curl -X PATCH --location "http://127.0.0.1:5000/todos/1/" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"Updated todo item\"
Expand All @@ -82,7 +86,5 @@ curl -X PATCH --location "http://127.0.0.1:5000/api/v1/todos/1" \

### Delete ToDo Item
```
curl -X DELETE --location "http://127.0.0.1:5000/api/v1/todos/1"
curl -X DELETE --location "http://127.0.0.1:5000/todos/1/"
```


11 changes: 4 additions & 7 deletions examples/02_pydantic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from pydantic import BaseModel
from sqlalchemy.orm import DeclarativeBase

from flask_muck import FlaskMuckApiView
from flask_muck import FlaskMuckApiView, FlaskMuck

app = Flask(__name__)
muck = FlaskMuck()
muck.init_app(app)


class Base(DeclarativeBase):
Expand All @@ -31,9 +33,6 @@ class TodoPayloadSchema(BaseModel):
text: str


api_blueprint = Blueprint("v1_api", __name__, url_prefix="/api/v1/")


class TodoApiView(FlaskMuckApiView):
session = db.session
api_name = "todos"
Expand All @@ -45,10 +44,8 @@ class TodoApiView(FlaskMuckApiView):
searchable_columns = [TodoModel.text]


TodoApiView.add_rules_to_blueprint(api_blueprint)
app.register_blueprint(api_blueprint)

if __name__ == "__main__":
with app.app_context():
db.create_all()
muck.register_muck_views([TodoApiView])
app.run(debug=True)
18 changes: 18 additions & 0 deletions examples/03_add_to_existing_api/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
flask = "*"
flask-sqlalchemy = "*"
pipenv = "*"
install = "*"
flask-muck = {file = "../.."}
webargs = "*"
pydantic = "*"

[dev-packages]

[requires]
python_version = "3.11"
Loading
Loading