🚀 First commit! Upload all files.

This commit is contained in:
rzmk 2022-09-19 20:25:39 -04:00
commit 0c2ac869a4
5 changed files with 68 additions and 0 deletions

9
.chalice/config.json Normal file
View file

@ -0,0 +1,9 @@
{
"version": "2.0",
"app_name": "crud-api-aws-chalice",
"stages": {
"dev": {
"api_gateway_stage": "api"
}
}
}

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.chalice/deployments/
.chalice/venv/
__pycache__

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# CRUD REST API using AWS Chalice
Details TBA.

52
app.py Normal file
View file

@ -0,0 +1,52 @@
from chalice import Chalice
import json
app = Chalice(app_name='crud-api-aws-chalice')
USERS = {}
# Example user in USERS:
# {
# "some_username123": {
# "username": "some_username123",
# "age": 20
# }
# }
@app.route("/")
def index():
return {'hello': 'world'}
# CREATE (POST)
@app.route('/users', methods=['POST'])
def create_user():
user_as_json = app.current_request.json_body
USERS[user_as_json["username"]] = user_as_json
return user_as_json
# READ (GET)
@app.route("/users", methods=["GET"])
def read_users():
return json.dumps(USERS)
# READ (GET)
@app.route("/users/{username}", methods=["GET"])
def read_user(username):
if username and username in USERS:
return json.dumps(USERS[username])
return {"error": f"'{username}' is not an existing user."}
# UPDATE (PUT)
@app.route("/users", methods=["PUT"])
def update_user():
user_as_json = app.current_request.json_body
USERS[user_as_json["username"]] = user_as_json
return user_as_json
# DELETE (DELETE)
@app.route("/users", methods=["DELETE"])
def delete_user():
user_as_json = app.current_request.json_body
if user_as_json["username"] in USERS:
del USERS[user_as_json["username"]]
return user_as_json

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
chalice