forked from bregman-arie/devops-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
abregman
committed
Dec 23, 2019
1 parent
dc802d4
commit e08c1cb
Showing
4 changed files
with
79 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python | ||
# coding=utf-8 | ||
|
||
from flask import Flask | ||
from flask import make_response | ||
|
||
import json | ||
from werkzeug.exceptions import NotFound | ||
|
||
|
||
app = Flask(__name__) | ||
|
||
with open("./users.json", "r") as f: | ||
users = json.load(f) | ||
|
||
|
||
@app.route("/", methods=['GET']) | ||
def index(): | ||
return pretty_json({ | ||
"resources": { | ||
"users": "/users", | ||
"user": "/users/<username>", | ||
}, | ||
"current_uri": "/" | ||
}) | ||
|
||
|
||
@app.route("/users", methods=['GET']) | ||
def all_users(): | ||
return pretty_json(users) | ||
|
||
|
||
@app.route("/users/<username>", methods=['GET']) | ||
def user_data(username): | ||
if username not in users: | ||
raise NotFound | ||
|
||
return pretty_json(users[username]) | ||
|
||
|
||
@app.route("/users/<username>/something", methods=['GET']) | ||
def user_something(username): | ||
raise NotImplementedError() | ||
|
||
|
||
def pretty_json(arg): | ||
response = make_response(json.dumps(arg, sort_keys=True, indent=4)) | ||
response.headers['Content-type'] = "application/json" | ||
return response | ||
|
||
|
||
def create_test_app(): | ||
app = Flask(__name__) | ||
return app | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters