Allow the use of resource uris#13
Conversation
|
I simplified the statement as suggested by @fatiherikli |
|
Are you considering to merge the pull request, and is there a new Pypi release planned? |
|
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? |
|
I believe it should be the default behavior. I don't see any situation when I would intentionally have double slashes in a url. |
|
I agree that it should be the default. I made it optional to ensure backward compatibility. I will update the patch accordingly |
|
@twigs could you please make it default behavior and update patch ? |
|
Sorry that it took me so long to make the simple change, totally forgot about this. |
|
@kadirpekel Is it possible to merge this pull request and release an updated PYPI version? |
Added custom sessions - see kadirpekel#14 - removing redundant slashes see kadirpekel#13 - better unicode as per https://github.com/bepress/hammock/blob/master/hammock.py
| HTTP_METHODS = ['get', 'options', 'head', 'post', 'put', 'patch', 'delete'] | ||
|
|
||
| def __init__(self, name=None, parent=None, append_slash=False, **kwargs): | ||
| def __init__(self, name=None, parent=None, append_slash=False, strip_slash=False, **kwargs): |
There was a problem hiding this comment.
strip_slash should be defaulted to True
strip_slash=True
| strip_slashes -- flag if you want to strip leading and trailing slashes from arguments | ||
| **kwargs -- `requests` session be initiated with if any available | ||
| """ | ||
| self._name = name |
There was a problem hiding this comment.
Check for strip_slash value
self._name = name.strip('/') if strip_slash else name
| """ | ||
| child = copy.copy(self) | ||
| child._name = name | ||
| child._name = child._name.strip('/') |
There was a problem hiding this comment.
check strip_slash value
child._name = name.strip('/') if self._strip_slash else name
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_slashwhich will remove leading and trailing slashes from the name when spawning newHammockinstances. This allows to use the URIs directly.current behavior::
with
strip_slash::can be used with
append_slash::