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

adds support for http middlewares #330

Merged
merged 19 commits into from
Aug 4, 2021
Merged

adds support for http middlewares #330

merged 19 commits into from
Aug 4, 2021

Conversation

baywet
Copy link
Member

@baywet baywet commented Jul 14, 2021

Summary

  • adds http client builder to allow for default middlewares and customization
  • renames chaining method
  • adds support for middleware options in dotnet abstractions and core

fixes #120

Generation Result

microsoft/kiota-samples#146

@baywet baywet added this to the Alpha milestone Jul 14, 2021
@baywet baywet self-assigned this Jul 14, 2021
Base automatically changed from feature/client-configuration to main July 15, 2021 11:15
@baywet baywet force-pushed the feature/middlewares branch from fed27a4 to b16df2f Compare July 15, 2021 11:51
@baywet baywet changed the base branch from main to feature/request-builders-ctors July 15, 2021 12:47
@baywet baywet force-pushed the feature/middlewares branch from b16df2f to ba07130 Compare July 15, 2021 12:48
@baywet baywet marked this pull request as ready for review July 16, 2021 14:25
@baywet baywet marked this pull request as draft July 16, 2021 14:29
@baywet baywet marked this pull request as ready for review July 16, 2021 18:30
@baywet baywet force-pushed the feature/request-builders-ctors branch from c7acaac to 276e900 Compare July 20, 2021 14:44
@baywet baywet force-pushed the feature/middlewares branch from f1e7b4f to f70d6c1 Compare July 21, 2021 13:34
@baywet baywet added the generator Issues or improvements relater to generation capabilities. label Jul 21, 2021
@@ -15,6 +16,22 @@ export class RequestInfo {
public queryParameters: Map<string, object> = new Map<string, object>(); //TODO: case insensitive
/** The Request Headers. */
public headers: Map<string, string> = new Map<string, string>(); //TODO: case insensitive
private _middlewareOptions = new Map<string, MiddlewareOption>(); //TODO: case insensitive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use something like [MiddlewareControl](https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/src/middleware/MiddlewareControl.ts instead of using _middlewareOptions. Please move addMiddlewareOptions and getMiddlewareOptions options to the MiddlewareControl.

  • A separate class for managing the properties as an object allows extensibility. A user can extend the MiddlewareControl class and flexibly customize their get and add middleware options or any property of the requestinfo class.
  • We can observe Single Responsibility Principle if we neatly segregate some functionalities into specific classes.
  • Avoids bulking up the RequestInfo class with too many methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was looking at the dotnet sdk which uses options but have uses control too. I'm not sure why we have a difference between languages today. @darrelmiller any guidance on options or control?
https://www.github.com/microsoftgraph/msgraph-sdk-dotnet-core/tree/dev/src%2FMicrosoft.Graph.Core%2FRequests%2FMiddleware%2FOptions%2FIMiddlewareOption.cs

We're attaching the options to request info to avoid passing multiple parameters between the layers. Request info is already being passed between layers. And the options or controls are related to the request info, which is why it felt natural to add them there. I'm not sure how you'd do it differently without having to pass additional parameters to the http core service?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both JS and .NET use the term Options. It looks like JS has a container for for middlewareOptions. .NET just uses a dictionary. I'm not sure why JS has the extra layer of indirection. Part of the confusion might be because the original requirement document talked about middleware controls. That notion got renamed to middleware options during implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context here. So I'm guessing we're sticking with options then.

@nikithauc
Copy link
Contributor

What is the reason to use predefined names such as fetch, okhttp as is and not a custom name like kiota-fetch or kiota-httpclient?

My concern is with

  • possible runtime issues incurred due to dependencies.
  • ambiguity in the code.

@baywet
Copy link
Member Author

baywet commented Jul 21, 2021

@nikithauc I'm not sure what you are referring to? The package name? A specific class?

Base automatically changed from feature/request-builders-ctors to main July 22, 2021 11:19
@baywet baywet requested a review from ramsessanchez as a code owner July 22, 2021 11:19
@baywet baywet force-pushed the feature/middlewares branch 2 times, most recently from 6c08c5f to 4f0bcb8 Compare July 28, 2021 16:39
using System.Net.Http;
using Microsoft.Kiota.Abstractions;

namespace Microsoft.Kiota.Http.HttpClient {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the likelihood of this namespace being used in the same context as System.Net.Http.HttpClient? If they show up in the same context, the naming collision can be confusing for the customers. Could we rename the last part or drop it altogether to bump the namespace one level up to Microsoft.Kiota.Http?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baywet, I think @nikithauc is referring to this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaah we had a long naming debate with @darrelmiller a long time ago.
I wanted to name this Microsoft.Kiota.Transport.Http leaving room for other transport implementations potentially in the future. Thoughts on that name? And for typescript we'd have something like @microsoft/kiota-transport-http.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are transport implementations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well one of them is HTTP of course, another one could be gRPC, etc...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think another common thing between HTTP and gRPC is that they are both protocols. So we can also have Microsoft.Kiota.Protocol.Http or Microsoft.Kiota.Protocols.Http as the namespace alternatives. I am OK with Microsoft.Kiota.Transport.Http too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think transport is correct here. Protocol is more accurate. For example, if we introduced WebSockets, we'd have:
Microsoft.Kiota.Protocol.Http
Microsoft.Kiota.Protocol.WebSocket

They use the same transport.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Microsoft.Kiota.Protocol.Http
Microsoft.Kiota.Protocol.WebSocket

The namespace looks meaningful.

Hypertext Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia documents, such as HTML. It was designed for communication between web browsers and web servers, but it can also be used for other purposes.

https://developer.mozilla.org/en-US/docs/Web/HTTP

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, protocol works for me as well. As this is a discussion on existing naming pattern, and as I'd like Darrel's "blessing" before changing the naming, I'm going to create a separate issue for that. Thanks for all the great suggestions!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikithauc nikithauc requested a review from andrueastman August 3, 2021 18:39
@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 4, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.4% 93.4% Coverage
0.0% 0.0% Duplication

@baywet baywet requested review from zengin and nikithauc August 4, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for middleware pipeline for request execution
5 participants