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

setup middleware pipeline for Ruby request adapter #1650

Closed
6 tasks done
Tracked by #1049
baywet opened this issue Jun 23, 2022 · 3 comments · Fixed by #2101
Closed
6 tasks done
Tracked by #1049

setup middleware pipeline for Ruby request adapter #1650

baywet opened this issue Jun 23, 2022 · 3 comments · Fixed by #2101
Assignees
Labels
enhancement New feature or request fixed Ruby
Milestone

Comments

@baywet
Copy link
Member

baywet commented Jun 23, 2022

related #120
related #635

To implement cross cutting concerns (like retrying on transient errors) we need the current http client to support middleware handlers, that is intercepting and change the request before it's sent over the wire, and the response before it's returned to the caller.

The first step here is to check the documentation of the client we're currently using to see whether it supports two things:

  • Defining and injecting middleware handlers in the requests execution pipeline
  • Defining and attaching request options to the request object (to be picked up by a middleware handler)

If it doesn't, we should design an overhead API for the native client that offers similar methods prototypes (what we did with TypeScript & fetch).

Additionally:

  • the abstractions needs to have a middleware request option interface defined
  • we need a client factory in the http library so consumers can get a client with the same middleware configuration as the request adapter is using by default.
  • the request information type needs to be able to carry request options
  • the options property property on request configuration needs to be of this new type (update the refiner)
  • generator method needs to pass the options to the request information object
  • the request adapter implementation needs to pass these options to the native request object
@osose-e
Copy link
Contributor

osose-e commented Aug 31, 2022

As NET::HTTP does not offer support for defining and injecting middleware handlers, there may be a suitable middleware that can be easily added on. I found these libraries:

Excon
"Excon was designed to be simple, fast and performant. It works great as a general HTTP(s) client and is particularly well suited to usage in API clients." Excon's last commit was within the last couple months, it is relatively active. This library offers a lot of features, like pipeline-ing requests; however, my fear is that this library is too big. It is also a wrapper library of net/http and not an adapter, so the current http microsoft kiota ruby package would have to be changed significantly. Excon is under an MIT license. The codebase is here.

@osose-e
Copy link
Contributor

osose-e commented Aug 31, 2022

Middleware
"Middleware is a library which provides a generalized implementation of the chain of responsibility pattern for Ruby." Middleware's last commit was in 2017, so it doesn't look as active as I'd like. However, the library seems to be much smaller than Excon and support mainly Middleware with handy tools like a logger, stack builder, etc. Middleware is under an MIT license. The codebase is here.

@baywet baywet added this to the Kiota post-GA milestone Dec 6, 2022
@baywet
Copy link
Member Author

baywet commented Dec 20, 2022

After some additional research we decided to adopt faraday for the time being.
Multiple reasons for that:

  1. it's popular, widely adopted well maintained.
  2. it provides support for middleware https://lostisland.github.io/faraday/middleware/
  3. it wraps around multiple http clients, leaving choice to users https://github.com/lostisland/awesome-faraday/#adapters

Some supporting evidence https://www.scrapingbee.com/blog/best-ruby-http-clients/

(Hey Osose in case you're watching, the research and the work you've done on Ruby helped a lot! 👋)

@baywet baywet self-assigned this Dec 20, 2022
@baywet baywet linked a pull request Dec 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed Ruby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants