Imperugo.HttpRequestToCurl 1.0.14

dotnet add package Imperugo.HttpRequestToCurl --version 1.0.14                
NuGet\Install-Package Imperugo.HttpRequestToCurl -Version 1.0.14                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Imperugo.HttpRequestToCurl" Version="1.0.14" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Imperugo.HttpRequestToCurl --version 1.0.14                
#r "nuget: Imperugo.HttpRequestToCurl, 1.0.14"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Imperugo.HttpRequestToCurl as a Cake Addin
#addin nuget:?package=Imperugo.HttpRequestToCurl&version=1.0.14

// Install Imperugo.HttpRequestToCurl as a Cake Tool
#tool nuget:?package=Imperugo.HttpRequestToCurl&version=1.0.14                

Imperugo.HttpRequestToCurl

Nuget Nuget GitHub

The idea of this library is to have a curl from an HttpRequest instance. The library produce a string that could be logged everywhere (console, db and so on).

Read the blog post here for more information.

Quickstart

Installation

Add the NuGet Package to your project:

dotnet add package Imperugo.HttpRequestToCurl

Usage

The useage is absolutely easy. Just add the reference and, anywhere in your code write this:

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Imperugo.HttpRequestToCurl.Sample.Models;

namespace Imperugo.HttpRequestToCurl.Sample.Controllers;

public class HomeController : Controller
{
    private readonly ILogger<HomeController> _logger;

    public HomeController(ILogger<HomeController> logger)
    {
        _logger = logger;
    }

    public async Task<IActionResult> IndexAsync()
    {
        var curl = await Request.ToCurlAsync();

        _logger.LogDebug(curl);
        return View();
    }
}

That code produces this output

dbug: Imperugo.HttpRequestToCurl.Sample.Controllers.HomeController[0]
      curl --location --request GET 'http://localhost:5069/'
      --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8' 
      --header 'Connection: keep-alive' 
      --header 'Host: localhost:5069' 
      --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' 
      --header 'Accept-Encoding: gzip, deflate, br' 
      --header 'Accept-Language: en-GB,en' 
      --header 'Cache-Control: max-age=0' 
      --header 'Upgrade-Insecure-Requests: 1' 
      --header 'sec-ch-ua: "Brave";v="107", "Chromium";v="107", "Not=A?Brand";v="24"' 
      --header 'sec-ch-ua-mobile: ?0' 
      --header 'sec-ch-ua-platform: "macOS"' 
      --header 'Sec-GPC: 1' 
      --header 'Sec-Fetch-Site: none' 
      --header 'Sec-Fetch-Mode: navigate' 
      --header 'Sec-Fetch-User: ?1' 
      --header 'Sec-Fetch-Dest: document'

If you want to use the --insecure you could do it with the specific parameter.

var curl = await Request.ToCurlAsync(insecure:true);

By default the ToCurl command generates an output that is compatible with the Bash but, if you are running on Windows or another system and you need a different output, you can specify it as parameter

Right now the supported output are:

  • Bash (default)
  • Command
  • Powershell
var curl = await Request.ToCurlAsync(Extensions.ToCurlOptions.CmdExe);

Sample

Take a look here

License

Imperugo.HttpRequestToCurl MIT licensed.

Contributing

Thanks to all the people who already contributed!

<a href="https://github.com/imperugo/HttpRequestToCurl/graphs/contributors"> <img src="https://contributors-img.web.app/image?repo=imperugo/HttpRequestToCurl" /> </a>

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Imperugo.HttpRequestToCurl:

Package Downloads
Imperugo.HttpRequestLogger

An extension method that create the cURL starting from an HttpRequest

Imperugo.HttpRequestLogger.Abstractions

An extension method that create the cURL starting from an HttpRequest

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.14 3,637 6/24/2024
1.0.13 1,081 4/30/2024
1.0.12 4,495 1/17/2023
1.0.11 304 1/17/2023
1.0.9 440 12/19/2022
1.0.8 871 12/5/2022
1.0.7 315 12/5/2022
1.0.6 334 12/5/2022
1.0.5 324 12/4/2022
1.0.4 322 12/4/2022
1.0.3 332 12/4/2022
1.0.2 336 12/4/2022
1.0.1 336 12/4/2022