-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Having had some time to review this code and also the Python requests library I am wondering if it is wise to create our own _HTTPClient class. The Python requests library exposes a module, not a class, so the behavior we are creating is potentially not consistent with how users expect requests to work.
One of primary goals is to simplify retrofitting existing applications that are calling the Graph using requests with our library.
Looking at the example code from PR #1 our calling pattern looks like:
from msgraph_sdk_python import HTTPClientFactory
requests = HTTPClientFactory.with_graph_middlewares(middlewares)
response = requests.get('/me')
If an existing application already has import requests, what happens when we call requests.get ?
From what I can tell the requests object now derives from Session, but has some of the requests api added. If we keep this approach we would need to implement them all to not break existing calls to requests.
Is there an advantage to sub-classing Session? Could the "with_graph_middlewares" not just mount the custom HttpAdapter? Perhaps it could return the session if the consumer decides they want further configure it? Perhaps it should accept an existing session if other configuration has already been done to it?
While our goal is to have similar architectural concepts across languages, the role of HttpClientFactory is to configure the native library to make HTTP requests in a way that is most suited for calling Microsoft Graph. It may not actually need to construct an instance of a HttpClient. That would be an example of us taking our foreign C# pattern and applying it to a different platform.
There is something not quite right about using a variable name to pretend that our class instance is the requests module, but then it actually be a Session and therefore you need to know to close requests, which is something a Python dev has never had to do before. There is something "uncanny valley" about this.
Thoughts? /cc @jobala @ddyett @MIchaelMainer