Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching an API resource by url #120

Open
mattaustin opened this issue Oct 21, 2015 · 1 comment
Open

Fetching an API resource by url #120

mattaustin opened this issue Oct 21, 2015 · 1 comment

Comments

@mattaustin
Copy link

I'm working with an API that does not provide ids/slugs for resource identifiers, as it expects you to use the url.

It's difficult to use Slumber to fetch a given resource outright (e.g. from a saved setting), such as 'http://example.com/api/resources/example-resource'.

I'm making extensive use of Slumber in my project, so I'd like to continue using it's 'api' object, rather than constructing requests manually.

If I create a new API object using the resource's url as the base url (not particularly desirable anyway), then I run in to the issue described in #28:

api = slumber.API('http://example.com/api/resources/example-resource/')
api.get()  # Just returns a slumber resource, and does not make the request

I've resorted to the following pattern for now:

api = slumber.API('http://example.com/api/')
resource_url = 'http://example.com/api/resources/example-resource/'
identity = resource_url.replace(api.resources.url(), '').rstrip('/')
response = api.resources(identity).get()

Is fetching a particular resource by it's absolute url a common pattern/requirement for others, and is this something that could be added to Slumber? I'm not sure what the desirable slumber-api would be, but if there is a good suggestion I could make a pull request.

@mattaustin
Copy link
Author

I've just discovered that using url_override is also a workaround - I'll use this method for the time-being, but there are comments for this kwarg that warn it's a bit of a hack.

api.resources(url_override='http://example.com/api/resources/example-resource/').get()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant