-
Notifications
You must be signed in to change notification settings - Fork 223
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
Allow to easily use GitHub Pagination. #4698
Comments
Hi @andreaTP |
This specific scenario is (GitHub paging) is what triggered the HeaderInspectionOptions feature. @andreaTP please confirm this would work for you! |
No, I haven't, but an interceptor needs some kind of synchronization in addition to the request and it's inherently not safe in case of concurrency/parallelism. e.g. I need strong guarantees of single threaded executions to be able to use it:
All in all, I'd consider |
This API has some shortcomings:
Considering the user's point of view:
I would say that there is room for improvement here 🙂 |
Thanks for the additional context here.
Here is the java equivalent (yes it's tied to OkHttp implementation)
This should be safe since the option is tied to the request information and doesn't cross any thread boundaries (unless the request execution is deferred to a thread pool by the application explicitly, in which case the simplest is to defer the whole block and not just the request execution).
There's no standard for pagination across REST APIs, or even standard ways to describe how the pagination is done. We considered adding support for generic pagination in kiota in the past, but this is something that we decided not to do in the end. #1499 I'd expect GitHub's pagination logic to be implemented in GitHub's core library for the time being. If we get enough demand for generic pagination support over time, we might want to consider it a new feature for kiota, but you're the first to ask for it at this time. |
Thanks for the feedback!
The problem of having the implementation tied to the request adapter implementation means that it needs to be ported to all the official and integrators libraries. I keep thinking that, at minimum, we should lift the burden to extract the headers(body in case of errors would be nice too) from a request, having a higher level API defined in Pair<Foo, Header> resp = client.foo.getWithHeader(); Is it reasonable? |
Fair enough, if we hoisted the option in the abstractions, multiple http implementations could reuse it, making the implementation for the consumer a detail. This getWithHeaders additional method has multiple drawbacks: complexifies the API surface, SDK size, might be a slippery slope when people want other things (trailers, etc...). I'd prefer avoiding it. |
An alternative would be to add methods to the WithHeaders<Foo> resp = adapter.getWithHeader(() -> client.foo.get());
var headers = resp.headers();
var foo = resp.value();
... thoughts? |
I'm going to share dotnet examples if you don't mind. regular scenario var user = await client.Users["jane"].GetAsync(); proxy scenario myAdapter.ReturnResponses = true;
var userResponse = await client.Users["jane"].GetAsync();
var headers = userResponse.Headers;
var user = userResponse as User; As I'm writing this, I'm realizing that it's most likely the only language which would allow us to do that without having to generate a proxy class for each model would be typescript thanks to the proxy object. I don't think there are equivalent in other languages, especially the statically typed ones, which would allow us to "augment" any type with the additional properties we care about. |
In Java there is Dynamic Proxy, but I would refrain to use it if possible. But we can try to iterate here(in C# no problem!): myAdapter.ReturnResponses = true;
var user = await client.Users["jane"].GetAsync();
var headers = user.Response.Headers; this design requires:
|
yes, I guess that'd be the only way to make my alternative suggestion work. |
I agree as a "general sentiment", but, in practice, there are several real world use-cases that would take advantage of such functionality.
I agree, this option won't be my favorite one, but, I was following along to try to get to an acceptable design ... Adding a |
I know I'm annoying with that but I'd really like to avoid a design that requires introducing a CLI flag. It makes the experience more complicated and hostile to new comers, adds maintenance burden, etc... |
I see this option pretty close to this, but, keeping the static methods away from the adapter is going to make it hard to discover/test/etc. |
For the example, I guess it'd look something like that var userResponse = await ResponseReader.ExecuteAsync(() => client.Users["jane"].GetAsync());
var headers = userResponse.Headers;
var user = userResponse.Value;
var statusCode = userResponse.StatusCode; |
Sorry for the delay here. |
The only languages that worry me are the ones that don't have a great generic support (Go) or that are dynamically typed. |
@darrelmiller I think we agreed on having your proposal using callbacks here, do you have a link or a write-up? |
I have a related use case. I need to read the location response header. My approach in Java is: NativeResponseHandler responseHandlerOption = new NativeResponseHandler();
ResponseHandlerOption opt = new ResponseHandlerOption();
opt.setResponseHandler(responseHandlerOption);
apiClient.admin().realms().byRealm(primary.getSpec().getRealm()).clients().post(createOption, r -> {r.options.add(opt);}); The problem is that I can't add to the options attribute because the collection is immutable. |
@Javatar81 which version of the abstractions are you using? this is a bug we fixed see microsoft/kiota-java#1240 |
I am using microsoft-kiota-abstractions 1.1.6 currently. BTW the client that I am implementing based on Kiota is for the Keycloak API. |
@Javatar81 try with latest 1.1.14 and let us know on a new issue in the kiota-java repo if this is still an issue (I don't want to side-track this thread) |
I would like to stress that it is often quite important to read the reponse headers. For example, when caching the responses from a 3rd party API, the " I am currently required to wrap every single call into code like this:
I like Kiota because the generated API is much nicer than what e.g. openapis swagger generator delivers. But not being able to have an easy way to both get the value and the headers is very frustrating. And the above is still a cruft because I put stuff into (I am using Java). The headers are very relevant more often than not. I haven't ever interfaced with another REST endpoint and not needed them. Caching, Pagination and Rate limiting are only three areas where that is important, and they come up often. Other use cases also require the headers. If anyone has an easier way to get the response headers, I am open for suggestions. Otherwise please consider exposing the response headers in the API far more easily. |
Thank you for the additional information. |
Is your feature request related to a problem? Please describe the problem.
Trying to use pagination with GitHub API as described here:
https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api
I have only 2 ways:
RequestHandler
to extract headers from the responses, but it's going to be challenging to use this mechanism in a concurrent systemClient library/SDK language
None
Describe the solution you'd like
It would be great to have a generic mechanism(maybe a callback?) to manually extract information from the raw Response.
Additional context
Do you already have a design in mind to solve this use-case?
I can implement something custom in my
RequestAdapter
but it would be nicer if we rely on some common interfaces.cc. @maxandersen
The text was updated successfully, but these errors were encountered: