RestCmd 1.0.9
dotnet add package RestCmd --version 1.0.9
NuGet\Install-Package RestCmd -Version 1.0.9
<PackageReference Include="RestCmd" Version="1.0.9" />
<PackageVersion Include="RestCmd" Version="1.0.9" />
<PackageReference Include="RestCmd" />
paket add RestCmd --version 1.0.9
#r "nuget: RestCmd, 1.0.9"
#:package RestCmd@1.0.9
#addin nuget:?package=RestCmd&version=1.0.9
#tool nuget:?package=RestCmd&version=1.0.9
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
headersof HeaderCollection type in all factory commands. TimeoutandReadWriteTimeoutpreviously has no effect.- Removed
Authorization,HeadersandMethodfromCommandclass. 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 | Versions 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. |
-
.NETFramework 4.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added support for Windows 7 SP1