Saad Abdullah
Saad Abdullah

Reputation: 2452

Pass relative URL in a restful url with slash or querystring. Which approach is better?

See the scenario below

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

which of the above scenario is restful and better? passing relative URL (/self/member/group/) as a part of url or path as a querystring?

Note: This (/self/member/group/) part is dynamic in terms of slashes. can be anything i.e. /groups or /venue/

Upvotes: 0

Views: 198

Answers (1)

cassiomolin
cassiomolin

Reputation: 131127

When I face a URL like:

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

I understand group is a subresource of member which is a subresource of self which is a subresource of the vendor resource. It is a hierarchy. If it's what you mean, go for this approach.

Otherwise, consider the query string approach and don't forget to URL encode the slashes:

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

Upvotes: 1

Related Questions