commit 0c2ac869a47287f64448cb25c2870fdde3aef608 Author: rzmk Date: Mon Sep 19 20:25:39 2022 -0400 :rocket: First commit! Upload all files. diff --git a/.chalice/config.json b/.chalice/config.json new file mode 100644 index 0000000..8bf7750 --- /dev/null +++ b/.chalice/config.json @@ -0,0 +1,9 @@ +{ + "version": "2.0", + "app_name": "crud-api-aws-chalice", + "stages": { + "dev": { + "api_gateway_stage": "api" + } + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf46139 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.chalice/deployments/ +.chalice/venv/ +__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c2a4ce --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# CRUD REST API using AWS Chalice + +Details TBA. diff --git a/app.py b/app.py new file mode 100644 index 0000000..705b77f --- /dev/null +++ b/app.py @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e4688da --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +chalice \ No newline at end of file