【发布时间】:2020-09-09 02:05:59
【问题描述】:
我想知道对于像提供注册页面来创建新用户这样的场景来说,最佳做法是什么。这里发生了两件不同的事情。1) 应用程序必须转发用户创建 html 页面,2) 用户创建论坛必须传递到端点以进行用户创建。
您是否应该将这两个流程组合为您的应用程序逻辑的一部分?还是应该由单独的 API 处理用户创建,而应用程序只提供 html?
选项 #1:
// Application routes serving HTML for GET and updating user state for POST
@app.route('/signup', methods=['GET', 'POST'])
return html--^ ^---- create new user
选项 #2:
// Application routes serving HTML for GET:
@app.route('/signup', methods=['GET'])
// Seperate REST API endpoint for user creation:
@app.route('/api/user/', method=['POST'])
【问题讨论】:
标签: rest web-applications architecture backend api-design