Raz.HeaderAttribute
1.0.1
dotnet add package Raz.HeaderAttribute --version 1.0.1
NuGet\Install-Package Raz.HeaderAttribute -Version 1.0.1
<PackageReference Include="Raz.HeaderAttribute" Version="1.0.1" />
paket add Raz.HeaderAttribute --version 1.0.1
#r "nuget: Raz.HeaderAttribute, 1.0.1"
// Install Raz.HeaderAttribute as a Cake Addin
#addin nuget:?package=Raz.HeaderAttribute&version=1.0.1
// Install Raz.HeaderAttribute as a Cake Tool
#tool nuget:?package=Raz.HeaderAttribute&version=1.0.1
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
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
- Right click on your solution
- click on the nuget package manager
- search for Raz.HeaderAttribute
- install 😃
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 😃
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. 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. |
This package has 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.
- Added ability to use parameter name as header key when header key is not specified