使用斜杠或查询字符串在相关URL中传递相对URL。哪种方法更好?

时间:2016-09-07 13:58:02

标签: rest

请参阅下面的方案

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 /

1 个答案:

答案 0 :(得分:1)

当我面对的网址如下:

http://localhost:8016/api/vendor/self/member/group/

我理解groupmember的子资源,它是self的子资源,是vendor资源的子资源。这是一个层次结构。如果这就是你的意思,那么就采用这种方法。

否则,请考虑查询字符串方法,不要忘记对斜杠进行URL编码:

http://localhost:8016/api/vendor?path=%2Fself%2Fmember%2Fgroup%2F