olsh / curl-to-csharp

curl to C# converter
https://curl.olsh.me
MIT License
224 stars 42 forks source link

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

Closed frankhommers closed 4 months ago

frankhommers commented 9 months ago

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

olsh commented 9 months ago

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

frankhommers commented 9 months ago

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.

olsh commented 9 months ago

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 ;)

frankhommers commented 4 months ago

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