forked from exizt/flask-restx-api-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
38 lines (28 loc) · 1.07 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, jsonify, request
from flask_restx import Api, Resource
app = Flask(__name__) # Flask 객체 선언.
api = Api(app) # Flask 객체에 Api 객체 등록
@api.route('/hello')
class HelloWorld(Resource):
def get(self):
return {"hello": "world!"}
def post(self):
return {"hello": "world!", "method": "post"}
@api.route('/test2')
class Test2(Resource):
@api.doc(params={'name': '파라미터 테스트 값 입력..'})
def get(self):
# name = request.json.get('name')
name = request.args.get('name')
return {"message": "test2", "name": name}
@api.param('name', '파라미터 테스트 값 입력..')
@api.param('name2', '파라미터 테스트 값 입력...')
@api.response(404, 'not found')
def post(self):
"""post 방식의 테스트 api 입니다."""
name = request.args.get('name')
return {"message": "test2", "method": "post", "name": name}
# flask run -p 5000
if __name__ == '__main__':
app.run(debug=True)
# app.run('0.0.0.0', port=5000, debug=True)