RestCmd 1.0.4

dotnet add package RestCmd --version 1.0.4
NuGet\Install-Package RestCmd -Version 1.0.4
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.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RestCmd --version 1.0.4
#r "nuget: RestCmd, 1.0.4"
#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 RestCmd as a Cake Addin
#addin nuget:?package=RestCmd&version=1.0.4

// Install RestCmd as a Cake Tool
#tool nuget:?package=RestCmd&version=1.0.4

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.

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.4 207 11/9/2023
1.0.3 96 11/8/2023
1.0.2 96 11/8/2023
1.0.1 98 11/6/2023

Summary of changes made in this release of the package.