GOR 1.0.1

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

// Install GOR as a Cake Tool
#tool nuget:?package=GOR&version=1.0.1

GOR (Generic Operation Response)

GOR by its acronym (Generic Operation Response) is a useful way to work with generic responses that speed up the evaluation of server responses. This helps developers to display better information in the responses that come from an HTTP request, such as GET, POST, DELETE or UPDATE.

How does it work?

Once we install the GOR package, we can use it as follows:

/// <summary>
/// Here we are returning 3 important things 
/// 1. Validation if there is an error
/// 2. A message to user or to the UI developer
/// 3. Status server code which it will be 200, 404, 500...
/// </summary>
/// <returns></returns>
public async Task<GenericOperationResponse<string>> DoSomething()
{
    // Write your logic here

    return new GenericOperationResponse<string>(false, "Message to user or front-end developer", HttpStatusCode.OK);
}

We also use the ENUM HttpStatusCode to indicate the response from the server.

HTTP response status codes

The HttpStatusCode enumeration contains the values of the status codes defined in RFC 2616 for HTTP 1.1. The status of an HTTP request is contained in the HttpWebResponse.StatusCode property. If the HttpWebRequest.AllowAutoRedirect property is false, the following enumeration values cause an exception to be thrown:

  • Ambiguous
  • Found
  • MultipleChoices
  • Redirect
  • RedirectKeepVerb
  • RedirectMethod
  • SeeOther
  • TemporaryRedirect

Another example:

public async Task<GenericOperationResponse<string>> DoSomething()
{
    try
    {
        // This can be any other model
        string response = "My DB response"; 

        return new GenericOperationResponse<string>(response, "Operation was OK", HttpStatusCode.OK);
    }
    catch (Exception ex)
    {
        // Here we tell the user or the UI: There is an error, the error and the server code
        return new GenericOperationResponse<string>(true, ex.ToString(), HttpStatusCode.InternalServerError);
    }
}

Why do we use GOR?

Generally in statements like try-catch or other places in the code we also prevent the API from having failures and stop working for no reason, that's why we create GOR and so we can map everything that really happens during execution.

An excellent recommendation is also to use ILogger to have better control. If you have any questions or concerns please feel free to contact me here https://twitter.com/HeyBaldur

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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.

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.1 4,119 7/5/2022
1.0.0 394 7/5/2022