File tree Expand file tree Collapse file tree 2 files changed +129
-3
lines changed
Expand file tree Collapse file tree 2 files changed +129
-3
lines changed Original file line number Diff line number Diff line change 1- # python-flask-seed
1+ # Python Flask Seed
22A python with flask seed project.
3+
4+ ## Dependencies
5+
6+ Install Python 3.5.x (x64)
7+ [ https://www.python.org/downloads/release/python-353/ ] ( https://www.python.org/downloads/release/python-353/ )
8+
9+ Install flask
10+ ``` bash
11+ $ pip install flask
12+ ```
13+
14+ ## Quick Start
15+
16+ ``` bash
17+ # Clone the repository
18+ $ git clone https://github.com/robertoachar/python-flask-seed.git
19+
20+ # Change the directory
21+ $ cd python-flask-seed
22+
23+ # Run
24+ $ python -m python_flask_seed
25+
26+ # Output from flask
27+ * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
28+ ```
29+
30+ ## Usage
31+
32+ ### Hello
33+
34+ #### Request
35+ ``` json
36+ GET / HTTP/1.1
37+ Host: localhost:5000
38+ ```
39+
40+ #### Response
41+ ``` json
42+ 200 OK
43+ {
44+ "message" : " Hello from flask!"
45+ }
46+ ```
47+
48+ ### Welcome
49+
50+ #### Request
51+ ``` json
52+ POST /welcome HTTP/1.1
53+ Host: localhost:5000
54+
55+ {
56+ "name" : " Roberto"
57+ }
58+ ```
59+
60+ #### Response
61+ ``` json
62+ 200 OK
63+ {
64+ "message" : " Hello Roberto!"
65+ }
66+ ```
67+
68+ #### Error handling
69+ ``` json
70+ 400 BAD REQUEST
71+ {
72+ "error" : " name is required"
73+ }
74+ ```
75+
76+ ## VSCode
77+
78+ #### Install extension Python 0.6.0 from Don Jayamanne
79+ ```
80+ ext install python
81+ ```
82+
83+ #### Install extension dependencies
84+
85+ ``` bash
86+ # Install autopep8
87+ $ pip install autopep8
88+
89+ # Install pylint
90+ $ pip install pylint
91+ ```
92+
93+ #### Set python path
94+
95+ File > Preferences > Settings > User Settings
96+ ``` json
97+ {
98+ "python.pythonPath" : " C:\\ Python35"
99+ }
100+ ```
101+
102+ ## Author
103+
104+ Roberto Achar
Original file line number Diff line number Diff line change 1- """ Entry point """
1+ from flask import Flask , jsonify , make_response , request
2+
3+ app = Flask ('python-flask-seed' )
4+
5+
6+ @app .route ('/' , methods = ['GET' ])
7+ def hello ():
8+ response = {'message' : 'Hello from flask!' }
9+ return make_response (jsonify (response ), 200 )
10+
11+
12+ @app .route ('/welcome' , methods = ['POST' ])
13+ def welcome ():
14+ content = request .get_json (silent = True , force = True )
15+
16+ try :
17+ message = 'Welcome %s!' % content ['name' ]
18+ response = {'message' : message }
19+ return make_response (jsonify (response ), 200 )
20+
21+ except Exception as ex :
22+ response = {'error' : 'name is required' }
23+ return make_response (jsonify (response ), 400 )
24+
25+
226if __name__ == '__main__' :
3- print ( 'Hello World!' )
27+ app . run ( host = '0.0.0.0' , port = 5000 )
You can’t perform that action at this time.
0 commit comments