0
我有两个服务运行在docker-compose
,frontend
和backend
,都使用烧瓶开发。使REST调用烧瓶服务运行在不同的端口
frontend:
restart: always
build: ./frontend
expose:
- "8000"
command: /usr/local/bin/gunicorn --bind :8000 run:application
backend:
restart: always
build: ./backend
expose:
- "9000"
command: /usr/local/bin/gunicorn --bind :9000 run:application
我托管在后端
@app.route('/api/weather', methods=['GET'])
def get_weather():
super_cool_function()
return jsonify({'temperature': 100})
什么是消耗在前端这个API的最好方法简单的REST API?我猜下面是一个办法,但我不知道应该是什么输入requests.get()
@app.route('/hello')
def hello():
r = requests.get()
return render_template('hello.html', temperature=r.json()['temperature'])
您是否考虑过使用url来使用您要使用的端点?这就是网络上的任何请求的工作原理。 – davidism
@davidism - 你的意思是'r = requests.get('http://example.com/api/weather:9000')'。基本上我在烧瓶中尝试'url_for'函数并且感到困惑 – kampta
这是标准方法吗? – kampta