Flask 설치
pip install flask
REST API
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, World!'
app.run(port=5000)
실행
python app.py
엔드포인트 설정
@app.route('/store', methods=['POST'])
def create_store():
pass
@app.route('/store/<string:name>')
def get_store(name):
pass
엔드포인트 리턴
from flask import jsonify
stores = [
....
]
@app.route('/store')
def get_stores():
return jsonify({'stores': stores})
JSON 처리
from flask import request
@app.route('/store', methods=['POST'])
def create_store():
request_data = request.get_json()
name = request_data['name']
...