corelibraries-devexpress-dot-dataaccess-dot-json-2dda7b15.md
An parameter that is used to add a custom HTTP header to JSON endpoint requests.
Namespace : DevExpress.DataAccess.Json
Assembly : DevExpress.DataAccess.v25.2.dll
NuGet Package : DevExpress.DataAccess
public class HeaderParameter :
DataSourceParameterBase
Public Class HeaderParameter
Inherits DataSourceParameterBase
The following members return HeaderParameter objects:
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:
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
};
Imports DevExpress.DataAccess
Imports DevExpress.DataAccess.Json
' ...
' Create a new JSON source.
Dim jsonSource = New UriJsonSource() With {.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 HeaderParameter("X-Date", GetType(String), String.Format("{0:yyyy-MM-dd}", Date.Today)),
New HeaderParameter("X-Id", GetType(Expression), New Expression("?ID"))
})
' "ID" is a report parameter whose value is used for the "X-Id" header parameter.
' Assign the JSON source to the data source.
Dim datasource = New JsonDataSource() With {.JsonSource = jsonSource}
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
};
Imports DevExpress.DataAccess
Imports DevExpress.DataAccess.Json
' ...
' Create a new JSON source.
Dim jsonSource = New UriJsonSource() With {.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 HeaderParameter("X-Date", GetType(String), String.Format("{0:yyyy-MM-dd}", Date.Today)),
New HeaderParameter("X-Id", GetType(Expression), New Expression("?ID"))
})
' "ID" is a report parameter whose value is used for the "X-Id" header parameter.
' Assign the JSON source to the data source.
Dim datasource = New JsonDataSource() With {.JsonSource = jsonSource}
Object DataSourceParameterBase HeaderParameter
See Also