HeaderParameter Class
An parameter that is used to add a custom HTTP header to JSON endpoint requests.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v24.2.dll
NuGet Package: DevExpress.DataAccess
Declaration
Related API Members
The following members return HeaderParameter objects:
Remarks
Use header parameters to add custom HTTP headers to JSON endpoint requests.
Add header parameters to HeaderParameterCollection and assign the collection to the UriJsonSource.HeaderParameters property.
The parameters are added to endpoint requests in the same order they occupy in the collection. Change the order of elements in the collection to reposition parameters in endpoint requests.
Specify the following properties to configure a header parameter:
- Name - the parameter name.
- Type - the parameter type. Set it to String to provide the parameter’s static value, or to Expression to provide an expression.
- Value - the parameter value.
You can use expressions to set the header parameter value. Specify an expression in the parameter’s Value and specify that the header parameter type is DevExpress.DataAccess.Expression. In DevExpress reports, you can use report parameters in an expression. Prepend the report parameter’s name with the ? character in the header parameter’s Value and specify that the header parameter type is DevExpress.DataAccess.Expression:
using DevExpress.DataAccess;
using DevExpress.DataAccess.Json;
// ...
// Create a new JSON source.
var jsonSource = new UriJsonSource() {
Uri = new Uri(@"https://localhost:44367/api/values")
};
// Create the "X-Date" and "X-Id" header parameters that are added to the JSON URI requests.
jsonSource.HeaderParameters.AddRange(new[] {
new HeaderParameter("X-Date", typeof(String), String.Format("{0:yyyy-MM-dd}", DateTime.Today)),
// "ID" is a report parameter whose value is used for the "X-Id" header parameter.
new HeaderParameter("X-Id", typeof(Expression), new Expression("?ID"))
});
// Assign the JSON source to the data source.
var datasource = new JsonDataSource() {
JsonSource = jsonSource
};
Example
The code sample below specifies a JSON endpoint and uses the X-Date and X-Id header parameters to add custom HTTP headers to JSON endpoint requests. The X-Id header parameter is bound to the ID report parameter.
using DevExpress.DataAccess;
using DevExpress.DataAccess.Json;
// ...
// Create a new JSON source.
var jsonSource = new UriJsonSource() {
Uri = new Uri(@"https://localhost:44367/api/values")
};
// Create the "X-Date" and "X-Id" header parameters that are added to the JSON URI requests.
jsonSource.HeaderParameters.AddRange(new[] {
new HeaderParameter("X-Date", typeof(String), String.Format("{0:yyyy-MM-dd}", DateTime.Today)),
// "ID" is a report parameter whose value is used for the "X-Id" header parameter.
new HeaderParameter("X-Id", typeof(Expression), new Expression("?ID"))
});
// Assign the JSON source to the data source.
var datasource = new JsonDataSource() {
JsonSource = jsonSource
};