Skip to content

Commit 53a5cdf

Browse files
committed
inital commit
0 parents  commit 53a5cdf

File tree

4 files changed

+238
-0
lines changed

4 files changed

+238
-0
lines changed

.gitignore

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/
139+
140+
Pipfile
141+
Pipfile.lock

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Overview
2+
3+
A super simple RESTful api created using Flask. The idea is to have a simple api that can be used with pipeline demos and proof of concepts.
4+
5+
## Installation
6+
7+
Requirements:
8+
9+
```sh
10+
virtualenv -p python3 venv
11+
source venv/bin/activate
12+
```
13+
14+
Next, run
15+
16+
```sh
17+
pip install -r requirements.txt
18+
```
19+
20+
to get the dependencies.
21+
22+
Finally run the api with
23+
24+
```sh
25+
python api.py
26+
```
27+
28+
## Example
29+
30+
Flask will run on http://127.0.0.1:5000/. Only one endpoint is available at ``days``.
31+
32+
```sh
33+
$ curl 127.0.0.1:5000/days
34+
[{"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"}]
35+
```
36+
37+
To return a single day pass in a number with Monday starting at 1.
38+
39+
```sh
40+
$ curl 127.0.0.1:5000/days/2
41+
{"day":{"id":2,"name":"Tuesday"}}
42+
```
43+
44+
Days will also accept a post message.
45+
46+
```sh
47+
$ curl -X POST 127.0.0.1:5000/days
48+
{"success":true}
49+
```
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

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from flask import Flask, jsonify, abort
2+
3+
days = [
4+
{"id": 1, "name": "Monday"},
5+
{"id": 2, "name": "Tuesday"},
6+
{"id": 3, "name": "Wednesday"},
7+
{"id": 4, "name": "Thursday"},
8+
{"id": 5, "name": "Friday"},
9+
{"id": 6, "name": "Saturday"},
10+
{"id": 7, "name": "Sunday"}
11+
]
12+
13+
api = Flask(__name__)
14+
15+
@api.route('/days', methods=['GET'])
16+
def get_days():
17+
return jsonify(days)
18+
19+
@api.route('/days/<int:day_id>', methods=['GET'])
20+
def get_day(day_id):
21+
day = [day for day in days if day['id'] == day_id]
22+
if len(day) == 0:
23+
abort(404)
24+
return jsonify({'day': day[0]})
25+
26+
@api.route('/days', methods=['POST'])
27+
def post_days():
28+
return jsonify({"success": True}), 201
29+
30+
if __name__ == '__main__':
31+
api.run()

requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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

0 commit comments

Comments
 (0)