请参阅下面的方案
http://localhost:8016/api/vendor/self/member/group/
@api.route('/<url_type:url_type>/<vendor_type:vendor_type>/<path:path>')
def mock_endpoint(url_type, vendor_type, path):
OR
http://localhost:8016/api/vendor?path=/self/member/group/
@api.route('/<url_type:url_type>/<vendor_type:vendor_type>/')
def mock_endpoint(url_type, vendor_type):
# get path queryparam here
以上哪种情况更安宁,更好?将相对URL(/ self / member / group /)作为url或path的一部分作为查询字符串传递?
注意:此(/ self / member / group /)部分在斜杠方面是动态的。可以是任何东西,即/ groups或/ venue /
答案 0 :(得分:1)
当我面对的网址如下:
http://localhost:8016/api/vendor/self/member/group/
我理解group
是member
的子资源,它是self
的子资源,是vendor
资源的子资源。这是一个层次结构。如果这就是你的意思,那么就采用这种方法。
否则,请考虑查询字符串方法,不要忘记对斜杠进行URL编码:
http://localhost:8016/api/vendor?path=%2Fself%2Fmember%2Fgroup%2F