Skip to content

Commit 74e7129

Browse files
committedMay 29, 2022
tidy up
1 parent 53a5cdf commit 74e7129

File tree

4 files changed

+32
-33
lines changed

4 files changed

+32
-33
lines changed
 

‎Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.7.11-slim
2+
3+
WORKDIR /python-api
4+
5+
COPY requirements.txt requirements.txt
6+
7+
RUN pip install -r requirements.txt
8+
9+
COPY . .
10+
11+
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]

‎README.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ A super simple RESTful api created using Flask. The idea is to have a simple api
77
Requirements:
88

99
```sh
10-
virtualenv -p python3 venv
11-
source venv/bin/activate
10+
python -m venv ./venv
11+
source .venv/bin/activate
1212
```
1313

1414
Next, run
@@ -27,31 +27,23 @@ python api.py
2727

2828
## Example
2929

30-
Flask will run on http://127.0.0.1:5000/. Only one endpoint is available at ``days``.
30+
Flask will run on http://127.0.0.1:5000/.
3131

3232
```sh
33-
$ curl 127.0.0.1:5000/days
33+
$ curl 127.0.0.1:5000/
3434
[{"id":1,"name":"Monday"},{"id":2,"name":"Tuesday"},{"id":3,"name":"Wednesday"},{"id":4,"name":"Thursday"},{"id":5,"name":"Friday"},{"id":6,"name":"Saturday"},{"id":7,"name":"Sunday"}]
3535
```
3636

3737
To return a single day pass in a number with Monday starting at 1.
3838

3939
```sh
40-
$ curl 127.0.0.1:5000/days/2
40+
$ curl 127.0.0.1:5000/2
4141
{"day":{"id":2,"name":"Tuesday"}}
4242
```
4343

4444
Days will also accept a post message.
4545

4646
```sh
47-
$ curl -X POST 127.0.0.1:5000/days
47+
$ curl -X POST 127.0.0.1:5000/
4848
{"success":true}
4949
```
50-
51-
```sh
52-
$ curl 127.0.0.1:5000/home
53-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
54-
<title>404 Not Found</title>
55-
<h1>Not Found</h1>
56-
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
57-
```

‎api.py ‎app.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
11
from flask import Flask, jsonify, abort
22

33
days = [
4-
{"id": 1, "name": "Monday"},
4+
{"id": 1, "name": "Monday"},
55
{"id": 2, "name": "Tuesday"},
66
{"id": 3, "name": "Wednesday"},
77
{"id": 4, "name": "Thursday"},
88
{"id": 5, "name": "Friday"},
99
{"id": 6, "name": "Saturday"},
10-
{"id": 7, "name": "Sunday"}
11-
]
10+
{"id": 7, "name": "Sunday"},
11+
]
1212

1313
api = Flask(__name__)
1414

15-
@api.route('/days', methods=['GET'])
15+
16+
@api.route("/", methods=["GET"])
1617
def get_days():
1718
return jsonify(days)
1819

19-
@api.route('/days/<int:day_id>', methods=['GET'])
20+
21+
@api.route("/<int:day_id>", methods=["GET"])
2022
def get_day(day_id):
21-
day = [day for day in days if day['id'] == day_id]
23+
day = [day for day in days if day["id"] == day_id]
2224
if len(day) == 0:
2325
abort(404)
24-
return jsonify({'day': day[0]})
26+
return jsonify({"day": day[0]})
2527

26-
@api.route('/days', methods=['POST'])
28+
29+
@api.route("/", methods=["POST"])
2730
def post_days():
2831
return jsonify({"success": True}), 201
2932

30-
if __name__ == '__main__':
31-
api.run()
33+
34+
if __name__ == "__main__":
35+
app.run(debug=True)

‎requirements.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
click==7.1.2
2-
Flask==1.1.2
3-
itsdangerous==1.1.0
4-
Jinja2==2.11.2
5-
MarkupSafe==1.1.1
6-
marshmallow==2.18.0
7-
marshmallow-jsonapi==0.23.2
8-
six==1.15.0
9-
Werkzeug==1.0.1
1+
flask

0 commit comments

Comments
 (0)