Raz.HeaderAttribute 1.0.1

This package makes a FromHeader attribute available in order to get values from request header straight from controller parameters in ASP.NET WebApi

Install-Package Raz.HeaderAttribute -Version 1.0.1
dotnet add package Raz.HeaderAttribute --version 1.0.1
<PackageReference Include="Raz.HeaderAttribute" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Raz.HeaderAttribute --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RazHeaderAttribute

Simple dotnet package for getting values from request headers in a clean way

Instructions


Setting up and using this library/package can be done in a few simple steps

  1. Install from nuget

    You can do this using one of two ways

    • Via nuget package manager console

    Simply type in the following command in the PM console

    Install-Package Raz.HeaderAttribute
    
    • Via nuget package manager GUI
    1. Right click on your solution
    2. click on the nuget package manager
    3. search for Raz.HeaderAttribute
    4. install :)
  2. Add the Attribute close to the controller parameter you wish to bind it to

    If you're already familiar with binding attributes this will be the simplest step. If you're not, C# has binding attributes that tell the framework where to get parameters specified in your controller from. For example, the [FromUri] attribute that tells the framework to pick that parameter from the URI or the [FromBody] one that tells the framework to pick the parameter from the request body for post requests.

    This package makes the attribute [FromHeader] available and also lets us specify the name of the header key we need and just like the pre-built attributes, it tries to bind to any primitive data type specified. Here's an example:

      ...
      using RazHeaderAttribute.Attributes;
    
      [Route("api/{controller}")]
      // Ewa-agoyin with sauce ;)
      public class YamAndBeansController : ApiController 
      {
          ...
          // GET api/yamandbeans
          [HttpGet]
          public IEnumerable<string> Get([FromHeader("page")] int page, [FromHeader] string rows)
          {
              // Print in the debug window to be sure our bound stuff are passed :)
              Debug.WriteLine($"My Debugger!!! Arrrrrggggh!!!!: Rows {rows}, Page {page}");
              ...
          }
      }
    

    And with this you're all setup and good. You can star this repo if you found this useful :)

RazHeaderAttribute

Simple dotnet package for getting values from request headers in a clean way

Instructions


Setting up and using this library/package can be done in a few simple steps

  1. Install from nuget

    You can do this using one of two ways

    • Via nuget package manager console

    Simply type in the following command in the PM console

    Install-Package Raz.HeaderAttribute
    
    • Via nuget package manager GUI
    1. Right click on your solution
    2. click on the nuget package manager
    3. search for Raz.HeaderAttribute
    4. install :)
  2. Add the Attribute close to the controller parameter you wish to bind it to

    If you're already familiar with binding attributes this will be the simplest step. If you're not, C# has binding attributes that tell the framework where to get parameters specified in your controller from. For example, the [FromUri] attribute that tells the framework to pick that parameter from the URI or the [FromBody] one that tells the framework to pick the parameter from the request body for post requests.

    This package makes the attribute [FromHeader] available and also lets us specify the name of the header key we need and just like the pre-built attributes, it tries to bind to any primitive data type specified. Here's an example:

      ...
      using RazHeaderAttribute.Attributes;
    
      [Route("api/{controller}")]
      // Ewa-agoyin with sauce ;)
      public class YamAndBeansController : ApiController 
      {
          ...
          // GET api/yamandbeans
          [HttpGet]
          public IEnumerable<string> Get([FromHeader("page")] int page, [FromHeader] string rows)
          {
              // Print in the debug window to be sure our bound stuff are passed :)
              Debug.WriteLine($"My Debugger!!! Arrrrrggggh!!!!: Rows {rows}, Page {page}");
              ...
          }
      }
    

    And with this you're all setup and good. You can star this repo if you found this useful :)

Release Notes

- Added ability to use parameter name as header key when header key is not specified

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 10,038 11/5/2017
1.0.0 262 11/4/2017