-
Notifications
You must be signed in to change notification settings - Fork 324
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 return of HTTP response headers from method invocations #400
Comments
@vinayada1 as well Agree, we didn't include the ability to expose the underlying HTTP semantics as part of the initial design here, but #399 is causing us to revisit this for the error case, and we should probably also expose it as an API for the successful case. |
Adding a proposal here:- The InvokeRequest and InvokeResponse should include all fields that are specific to http and gRPC protocols. We will treat http as a superset instead of having separate methods to invoke http and gRPC which allows more flexibility to the user. Service invocation can use the method below:- The Invoke Request will look as below:-
The Invoke Response will look as below:-
The GrpcStatusInfo will look as below:-
For throwing exceptions, we will use the format below:- |
I like having access to the response headers, but I’m not so fond of needing to use a lower level method to achieve it. There really isn’t that much that the SDK adds on top of making the call to the Dapr instance. Using the proposed I’d propose to aligning this more to how the state API methods work: TValue GetState<TValue>(...)
StateEntry<TValue> GetStateEntry<TValue>(...) For service invocation, this would look like: // Existing method:
TResponse InvokeMethod<TResponse>(string appId, string methodName, ...)
// Extra method to add:
ServiceInvocationResponse<TResponse> InvokeMethodRaw<TResponse>(
string appId, string methodName, ...) The public class InvokeResponse<TResponse>
{
public InvokeRequest Request { get; set; }
public TResponse Body { get; set; }
public string ContentType { get; set; }
public Dictionary<string, string> Headers { get; set; }
public int? HttpStatusCode { get; set; }
public GrpcStatusInfo GrpcStatusInfo { get; set; }
} Both the Not sure if ServiceInvocationResponse<TResponse> InvokeMethod<TResponse>(...)
TResponse InvokeMethodUnwrap<TResponse>(...) |
@amolenk - can you provide some more info about what you're looking for with headers - which headers? what's the use case? |
@rynowak The main use case for response headers is making calls to services that do not return all information in the response body, but include useful info in response headers as well. For example, a service that returns customer information but also includes an Etag response header to use for optimistic concurrency checks when updating the customer info. I think this issue is bigger than only response headers though, because it's equally important to have access to the HTTP status code and error messages. I don't want to have to choose between the SDK doing serialization/deserialization for me and having access to headers/status/error info. |
@amolenk - thanks, that's the kind of details I was looking for. @vinayada1 is driving the work here, but the last discussion we had was around incorporating your feedback. The rough plan is to have 3 families of methods:
The first two of these would throw an exception on non-2XX status that includes the Your thoughts? Does this match what you expected? |
@rynowak Yes, looks good to me. I think this would cover all scenarios. |
Could there also be a way of extracting HTTP headers sent by an application with the response? For example, if the response was an opaque set of bytes, the
Content-Type
response header might be needed in order to differentiate between multiple types of data. Something of this sort:@amolenk suggested a variation on this theme:
The service that's being called may be an HTTP service, but it could also be a gRPC service. So I'd do it slightly different:
Alternatively, at that point it may even be better to make separate invoke methods for Http and gRPC, like InvokeHttpMethod and InvokeGrpcMethod. The abstraction is already a bit leaky due to the need for the HttpExtension object.
RELEASE NOTE: ADD HTTP status code for error in method invocation.
The text was updated successfully, but these errors were encountered: