curl-to-csharp icon indicating copy to clipboard operation
curl-to-csharp copied to clipboard

Don't convert to code, but return an actual populated HttpRequestMessage.

Open frankhommers opened this issue 1 year ago • 3 comments

Hi there,

I would like to use this component to be able to configure a request fully in a configuration file, load it and run it from the same project.

So therefore instead of the ToCsharp function which returns code, I am thinking of ToHttpRequestMessage function, which actually returns that so I can fire the request directly from the CommandLineParsing code.

Is this feasible?

Thanks,

Frank

frankhommers avatar Feb 01 '24 00:02 frankhommers

Hi @frankhommers

Well, some curl options require configuration of HttpClientHandler, using HttpRequestMessage is not enough.

Probably this will be useful for you. In this code, we convert curl command to code, compile the generated code, execute it and read content of HttpResponseMessage. https://github.com/olsh/curl-to-csharp/blob/4b61d1f79013f3ad414ed599dd6282b32bc73000/src/CurlToCSharp.IntegrationTests/RequestsTests.cs#L102-L125

olsh avatar Feb 01 '24 05:02 olsh

Thanks!

This is actually a bit too heavy I guess. I want to run it on an embedded device. I guess I need SDK for this, but I'd like the runtime only.

May original idea still stands, but I according to your opinion it must return HttpClientHandler and a HttpRequestMessage.

frankhommers avatar Feb 01 '24 09:02 frankhommers

The scripting API doesn't require an SDK. Please find more info here. https://github.com/dotnet/roslyn/blob/main/docs/wiki/Scripting-API-Samples.md

I think that it's possible to return configured objects, but I don't have time to implement it. So, PR is welcome ;)

olsh avatar Feb 01 '24 11:02 olsh

I don't have time either, and I have moved on to a different solution. So no problem ;-)

frankhommers avatar Jun 24 '24 12:06 frankhommers