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

Add PostContent/PutContent overloads on IRESTFulApiFactoryClient #71

Closed
Catalin-Andronie opened this issue Mar 28, 2023 · 5 comments
Closed

Comments

@Catalin-Andronie
Copy link
Contributor

Catalin-Andronie commented Mar 28, 2023

Next overloads on the IRESTFulApiFactoryClient allow for scenarios where multipart form-data payload can be sent to the server and still have the response validation is place.

In some scenarios, it is useful to return the HttpResponseMessage directly and allow the client to deserialize the response. In other scenarios, the TResponse is the expected type of deserialization.

namespace RESTFulSense.Clients
{
    public partial interface IRESTFulApiFactoryClient
    {
        ValueTask<HttpResponseMessage> PostContentAsync(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
        ValueTask<TResponse> PostContentAsync<TResult>(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);

        ValueTask<HttpResponseMessage> PutContentAsync(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
        ValueTask<TResponse> PutContentAsync<TResult>(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
    }
}

namespace RESTFulSense.WebAssembly.Clients
{
    public partial interface IRESTFulApiFactoryClient
    {
        ValueTask<HttpResponseMessage> PostContentAsync(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
        ValueTask<TResponse> PostContentAsync<TResult>(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);

        ValueTask<HttpResponseMessage> PutContentAsync(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
        ValueTask<TResponse> PutContentAsync<TResult>(string relativeUrl, HttpContent content, CancellationToken cancellationToken = default);
    }
}
@Catalin-Andronie
Copy link
Contributor Author

@BrianLParker What do you think about this proposal?

@hassanhabib
Copy link
Owner

@Catalin-Andronie what are you going to serialize the response to other than what's already in place?

@Catalin-Andronie
Copy link
Contributor Author

Catalin-Andronie commented Apr 1, 2023

@Catalin-Andronie what are you going to serialize the response to other than what's already in place?

@hassanhabib For the OpenAI Audio endpoint, we can specify the response type (e.g: text, srt, vvt, json) in the request, which means the response cannot be serialized to JSON in all cases. Because of it, I propose two overloads:

  • ValueTask<TResponse> PostContentAsync<TResult>() - for serializing the response to JSON directly in the library
  • ValueTask<HttpResponseMessage> PostContentAsync() - allow the caller to serialize the response as needed for response types text, srt, vvt

@hassanhabib If you got other proposals I am open to not returning HttpResponseMessage directly, but it seems that currently, the library considers all responses as JSON.

@hassanhabib
Copy link
Owner

@BrianLParker @cjdutoit thoughts?

@Catalin-Andronie
Copy link
Contributor Author

Closing this, since now RESTFulSense has support to post a multipart-form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants