-
Notifications
You must be signed in to change notification settings - Fork 1
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
Build out http helper class #36
Conversation
return _decorator(fn) if fn else _decorator | ||
|
||
@measure_time | ||
def get(self, url: str, headers: dict = {}) -> requests.Response: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice usability enhancement for all of these would be to allow passing in an optional dictionary of query parameters that we could encode for them, rather than making the user do it each time. This would map to the params
argument in requests.
canvas_sdk/utils/http.py
Outdated
return self.session.get(url, headers=headers) | ||
|
||
@measure_time | ||
def post(self, url: str, json: dict | None = None, headers: dict = {}) -> requests.Response: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to allow post, put, and patch to send non-JSON request bodies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we want to keep it simple for now, and if there is a need to add in more other uses like those (files, etc), we'll add them. it'll be simple enough since we're just copying the same api as the requests library and passing in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. The specific non-JSON use case I was thinking about was for request bodies that are application/x-www-form-urlencoded
-- like requesting an OAuth token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good one! i'll add it
https://canvasmedical.atlassian.net/browse/KOALA-1335
An abstraction on the requests library with the following methods:
get
post
put
patch
creates a requests session and then passes calls through session methods. also a statsd wrapper to measure the timing of each call.
still todo: