hammock icon indicating copy to clipboard operation
hammock copied to clipboard

Allow the use of resource uris

Open twigs opened this issue 11 years ago • 8 comments

Some rest based APIs use resource URIs to point to specific, usually related resources. These URIs are usually absolute paths for the domain hosting the API and are returned by previous API calls. At the moment there is no way to use those URIs directly with hammock. You either have to modify the uri by removing leading slashes or to use requests directly.

This proposed patch adds a new keyword strip_slash which will remove leading and trailing slashes from the name when spawning new Hammock instances. This allows to use the URIs directly.

current behavior::

import hammock
api = hammock.Hammock('http://localhost:8000')
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri) # note the double slash after domain:port
http://localhost:8000//api/v1/users/4711/  

with strip_slash::

import hammock
api = hammock.Hammock('http://localhost:8000', strip_slash=True)
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri) 
http://localhost:8000/api/v1/users/4711

can be used with append_slash::

import hammock
api = hammock.Hammock('http://localhost:8000', strip_slash=True, append_slash=True)
my_ressource_uri = '/api/v1/users/4711/'
print api(my_ressource_uri) 
http://localhost:8000/api/v1/users/4711/

twigs avatar May 28 '13 07:05 twigs

I simplified the statement as suggested by @fatiherikli

twigs avatar May 29 '13 10:05 twigs

Are you considering to merge the pull request, and is there a new Pypi release planned?

twigs avatar Jun 18 '13 19:06 twigs

I'm not certain and sure about for exposing this functionality though an optional argument. I prefer this to be default behavior or not exist at all. What you think?

kadirpekel avatar Jun 19 '13 09:06 kadirpekel

I believe it should be the default behavior. I don't see any situation when I would intentionally have double slashes in a url.

vitormazzi avatar Jun 19 '13 20:06 vitormazzi

I agree that it should be the default. I made it optional to ensure backward compatibility. I will update the patch accordingly

twigs avatar Jun 24 '13 10:06 twigs

@twigs could you please make it default behavior and update patch ?

mesuutt avatar Nov 05 '13 10:11 mesuutt

Sorry that it took me so long to make the simple change, totally forgot about this.

twigs avatar Nov 05 '13 12:11 twigs

@kadirpekel Is it possible to merge this pull request and release an updated PYPI version?

twigs avatar Nov 07 '13 10:11 twigs