F3R4L.DevPack.Api 1.0.5

dotnet add package F3R4L.DevPack.Api --version 1.0.5
                    
NuGet\Install-Package F3R4L.DevPack.Api -Version 1.0.5
                    
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="F3R4L.DevPack.Api" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="F3R4L.DevPack.Api" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="F3R4L.DevPack.Api" />
                    
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 F3R4L.DevPack.Api --version 1.0.5
                    
#r "nuget: F3R4L.DevPack.Api, 1.0.5"
                    
#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 F3R4L.DevPack.Api@1.0.5
                    
#: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=F3R4L.DevPack.Api&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=F3R4L.DevPack.Api&version=1.0.5
                    
Install as a Cake Tool

This is a library intended to simplify making REST API calls. There are two possible ways of using it.

Simplified

The first is the original, more simple manner. Create a new class that inherits from one of the "Endpoint" classes. These are named per the Http VERB they are used for, and have variants depending on the request and response types:

  • GetEndpoint
  • PostEndpoint
  • PutEndpoint
  • PatchEndpoint
  • DeleteEndpoint

Each endpoint type has sub-variants that may be used, dependant on the number of request and / or response types. An example endpoint for a POST with a user defined request type of "TestRequest" & a response type of "TestResponse" would be:

<details> <summary>Example</summary>

public class TestPostEndpoint : PostEndpoint<TestRequest, TestResponse>
{
    public TestPostEndpoint(string hostName, string endpoint)
    : base(hostName, endpoint) { }
}

</details>

Enhanced

An enhanced functionality version switches the base classes to the following:

  • AuditableGetEndpoint
  • AuditablePostEndpoint
  • AuditablePutEndpoint
  • AuditablePatchEndpoint
  • AuditableDeleteEndpoint

Again, each endpoint type has sub-variants that may be used, dependant on the number of request and / or response types. An example endpoint for a POST with a user defined request type of "TestRequest" & a response type of "TestResponse" would be:

<details> <summary>Example</summary>

public class TestPostEndpoint : AuditablePostEndpoint<TestRequest, TestResponse>
{
    public TestPostEndpoint(string hostName, string endpoint)
    : base(hostName, endpoint) { }
}

</details>

Differences

The simplified system attempts to return an object of type "TestResponse": if the response form the server cannot be deserialised to the target type, an "ApiCallException" is throw that contains the details of the problem. The enhanced system will always return an "AuditContainer":

<details>

<summary><bold>AuditContainer</bold></summary>

    public class AuditContainer
    {
        public string Url { get; set; }
        public HttpStatusCode StatusCode { get; set; }
        public string ErrorMessage { get; set; }
        public string ResponseMessage { get; set; }
    }
  • Url: The full URL of the request made
  • StatusCode: The HttpStatusCode returned by the server
  • ErrorMessage: If the request failed, this will contain the error message returned by the server
  • ResponseMessage: If the request failed, this will contain the response message returned by the server </details>

<details>

<summary><bold>AuditContainer<T></bold></summary>

    public class AuditContainer<T>
    {
        public string Url { get; set; }
        public HttpStatusCode StatusCode { get; set; }
        public string ErrorMessage { get; set; }
        public string ResponseMessage { get; set; }
        
        public ObjectContainer<T> Request { get; set; }
        public ObjectContainer<T> Response { get; set; }
    }
  • Url: The full URL of the request made
  • StatusCode: The HttpStatusCode returned by the server
  • ErrorMessage: If the request failed, this will contain the error message returned by the server
  • ResponseMessage: If the request failed, this will contain the response message returned by the server
  • Request: An ObjectContainer containing the request object and the actual JSON string that was sent
  • Response: An ObjectContainer containing the response object and the actual JSON string that was received

Only one of the Request or Response properties will be populated, depending on the type of endpoint used. </details>

<details>

<summary><bold>AuditContainer<TIn, TOut></bold></summary>

    public class AuditContainer<TIn, TOut>
    {
        public string Url { get; set; }
        public HttpStatusCode StatusCode { get; set; }
        public string ErrorMessage { get; set; }
        public string ResponseMessage { get; set; }
        
        public ObjectContainer<TIn> Request { get; set; }
        public ObjectContainer<TOut> Response { get; set; }
    }
  • Url: The full URL of the request made
  • StatusCode: The HttpStatusCode returned by the server
  • ErrorMessage: If the request failed, this will contain the error message returned by the server
  • ResponseMessage: If the request failed, this will contain the response message returned by the server
  • Request: An ObjectContainer containing the request object and the actual JSON string that was sent
  • Response: An ObjectContainer containing the response object and the actual JSON string that was received </details>

Dependency Injection

To your project, add a reference to the F3R4L.DevPack.Api package. Then, in your injection container, add the following using line:


using F3R4L.DevPack.Api.DependencyInjection;

Then, add the following line to the code:


services.AddApiBindings();

Usage

To your class, add the following using line:


using F3R4L.DevPack.Api.Services;

Then, add the following to your class constructor:


IApiService apiService

Add a private field to your class to contain the injected IApiService, which can be used to make the API calls. For example:


            var endpoint = new TestGetEndpoint(_baseUrl, "/get");
            var response = await _objectUnderTest.GetAsync(endpoint);

'''

When "TestGetEndpoint" derives from "GetEndpoint", the variable response will be of type "T" that you defined in the endpoint class. 
If "TestGetEndpoint" derives from "AuditableGetEndpoint", the variable response will be of type "AuditContainer<T>" that you defined in the endpoint class.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.5 114 8/5/2026
1.0.4 122 6/30/2026
1.0.3 145 1/6/2026
1.0.2 280 5/20/2024
1.0.0 179 5/2/2024