RestCmd 1.0.9

dotnet add package RestCmd --version 1.0.9
                    
NuGet\Install-Package RestCmd -Version 1.0.9
                    
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="RestCmd" Version="1.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RestCmd" Version="1.0.9" />
                    
Directory.Packages.props
<PackageReference Include="RestCmd" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RestCmd --version 1.0.9
                    
#r "nuget: RestCmd, 1.0.9"
                    
#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.
#:package RestCmd@1.0.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RestCmd&version=1.0.9
                    
Install as a Cake Addin
#tool nuget:?package=RestCmd&version=1.0.9
                    
Install as a Cake Tool

RestCmd API Command

RestCmd is a lightweight REST library based on HttpWebRequest that executes API commands. This library runs on .NET Framework 4.0+. This was specifically created on the platform to address legacy programs that still runs on lower versions of the .NET platform. There are lots of REST libraries for newer versions of the .NET. The most popular one is RestSharp.

What's new in version 1.0.9.0?

The Upload() method previously supported FileUpload class only. Now it takes an IMultipart interface that handles both file input and the rest.

Changes:

  • Added a new optional argument headers of HeaderCollection type in all factory commands.
  • Timeout and ReadWriteTimeout previously has no effect.
  • Removed Authorization, Headers and Method from Command class. It had no purpose.

Basic Usage

The library utilizes the factory pattern. A factory is created with mandatory properties like BaseUri, Authorization, timeouts and headers. The factory object can then be used for successive commands.

To create a new Factory:

 Factory restCmdFactory = new Factory {
     BaseUri = "https://api.restful-api.dev",
     ReadWriteTimeout = 1000,
     Timeout = 1000,
 };

We used the restful-api.dev ready-to-use endpoint for convenience.

Factory has an Authorization Property. It is requires a JWT token. The "Bearer " prefix is automatically prepended.

Upon creation, restCmdFactory can now create a command:

Command cmd = restCmdFactory.Get("/", "objects");

The Get command will fetch data from the default path (/) and objects resource. The objects resource is the resource id. Afterwards, we will call on Execute() to retrieve the contents of the resource.

var res = cmd.Execute<object>();

The Execute method on cmd will retrieve the contents and will attempt to convert it as an object, since it was specified that the result should be an object. Upon inspecting the response, the result should look like an enumerated object:

[
  {
    "id": "1",
    "name": "Google Pixel 6 Pro",
    "data": {
      "color": "Cloudy White",
      "capacity": "128 GB"
    }
  },
  {
    "id": "2",
    "name": "Apple iPhone 12 Mini, 256GB, Blue",
    "data": null
  },
  {
    "id": "3",
    "name": "Apple iPhone 12 Pro Max",
    "data": {
      "color": "Cloudy White",
      "capacity GB": 512
    }
  },
  {
    "id": "4",
    "name": "Apple iPhone 11, 64GB",
    "data": {
      "price": 389.99,
      "color": "Purple"
    }
  },
  {
    "id": "5",
    "name": "Samsung Galaxy Z Fold2",
    "data": {
      "price": 689.99,
      "color": "Brown"
    }
  },
  {
    "id": "6",
    "name": "Apple AirPods",
    "data": {
      "generation": "3rd",
      "price": 120
    }
  },
  {
    "id": "7",
    "name": "Apple MacBook Pro 16",
    "data": {
      "year": 2019,
      "price": 1849.99,
      "CPU model": "Intel Core i9",
      "Hard disk size": "1 TB"
    }
  },
  {
    "id": "8",
    "name": "Apple Watch Series 8",
    "data": {
      "Strap Colour": "Elderberry",
      "Case Size": "41mm"
    }
  },
  {
    "id": "9",
    "name": "Beats Studio3 Wireless",
    "data": {
      "Color": "Red",
      "Description": "High-performance wireless noise cancelling headphones"
    }
  },
  {
    "id": "10",
    "name": "Apple iPad Mini 5th Gen",
    "data": {
      "Capacity": "64 GB",
      "Screen size": 7.9
    }
  },
  {
    "id": "11",
    "name": "Apple iPad Mini 5th Gen",
    "data": {
      "Capacity": "254 GB",
      "Screen size": 7.9
    }
  },
  {
    "id": "12",
    "name": "Apple iPad Air",
    "data": {
      "Generation": "4th",
      "Price": "419.99",
      "Capacity": "64 GB"
    }
  },
  {
    "id": "13",
    "name": "Apple iPad Air",
    "data": {
      "Generation": "4th",
      "Price": "519.99",
      "Capacity": "256 GB"
    }
  }
]

The result is an enumerated object. We can't put out an image of the actual result.

To summarize the actual code:

 Factory restCmdFactory = new Factory {
     BaseUri = "https://api.restful-api.dev",
     ReadWriteTimeout = 1000,
     Timeout = 1000,
 };
 // Specify the resource
 Command cmd = restCmdFactory.Get("/", "objects");
 // Get the resource
 var res = cmd.Execute<object>();
 // Process the result here...

You can explore other REST commands supported by this library for more information.

Written with StackEdit.

Product Compatible and additional computed target framework versions.
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9 209 9/11/2025
1.0.8 256 8/29/2025
1.0.7 247 8/29/2025
1.0.6 263 8/28/2025
1.0.5 212 7/10/2024
1.0.4 311 11/9/2023
1.0.3 217 11/8/2023 1.0.3 is deprecated because it is no longer maintained and has critical bugs.
1.0.2 227 11/8/2023 1.0.2 is deprecated because it is no longer maintained and has critical bugs.
1.0.1 204 11/6/2023 1.0.1 is deprecated because it is no longer maintained and has critical bugs.

Added support for Windows 7 SP1