ResponseSchemaHeader 0.7.0

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

// Install ResponseSchemaHeader as a Cake Tool
#tool nuget:?package=ResponseSchemaHeader&version=0.7.0

ResponseSchemaHeader

ASP.NET Core API middleware that allows client to specify what part of the response they need, and cuts out everything else before it's sent to the client.

Features

  • One line initialization
  • Supports object and array responses
  • Supports nested properties
  • Supported response content types:
    • JSON

Initialization

To start using the middleware just add UseResponseSchemaHeader into Statup.cs before UseEndpoints:

public void Configure(IApplicationBuilder app)
{
    app.UseResponseSchemaHeader();
}

Usage

Now your client is able to add ResponseSchema header to any request, and ASP.NET will remove any properties that are not listed there. If client needs everything to be returned, ResponseSchema header can be omitted.

ResponseSchema should have following structure:

[ 
    "topLevelProperty1", 
    "topLevelProperty2", 
    {
        "topLevelProperty3": [
            "nestedProperty1"
        ] 
    } 
]

If all nested properties from topLevelProperty3 need to be included, add it as another string array item.

For example, let's say your action returns following information:

[
    {
        "registration": "AA07AMM",
        "modelCode": "nissan-note",
        "color": "Turquoise",
        "year": 2007,
        "vehicleModel": {
            "code": "nissan-note",
            "manufacturerCode": "nissan",
            "name": "NOTE",
            "manufacturer": {
                "code": "nissan",
                "name": "NISSAN"
            }
        }
    },
    {
        "registration": "AAC792H",
        "modelCode": "hyundai-i10",
        "color": "Silver",
        "year": 1975,
        "vehicleModel": {
            "code": "volkswagen-up",
            "manufacturerCode": "volkswagen",
            "name": "UP",
            "manufacturer": {
                "code": "volkswagen",
                "name": "VOLKSWAGEN"
            }
        }
    },

And you only need registration and vehicleModel.code on your client. After adding this header to the request (it's case insensitive by default):

ResponseSchema: [ "Registration", "ModelCode", { "vehicleModel": [ "code" ] } ]

Response will be:

[
    {
        "registration": "AA07AMM",
        "vehicleModel": {
            "code": "nissan-note"
        }
    },
    {
        "registration": "AAY452D",
        "vehicleModel": {
            "code": "volkswagen-up"
        }
    }
]
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 netcoreapp2.0 is compatible.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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
0.7.0 288 7/7/2021