HeaderParameter Class

An parameter that is used to add a custom HTTP header to JSON endpoint requests.

Namespace: DevExpress.DataAccess.Json

Assembly: DevExpress.DataAccess.v20.1.dll

Declaration

public class HeaderParameter :
    DataSourceParameterBase
Public Class HeaderParameter
    Inherits DataSourceParameterBase

Returned By

The HeaderParameterCollection.Item[String] property returns an instance of HeaderParameter.

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:

using DevExpress.DataAccess;
using DevExpress.DataAccess.Json;
// ...
// Specify the current date as the path parameter value. Format the date as 2020-01-31.
jsonSource.HeaderParameters.Add(new HeaderParameter("date", typeof(Expression), new Expression("FormatString('{0:yyyy-MM-dd}',Today())")));

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;
// ...
// The "ReportDateParameter" is a DevExpress report parameter whose value is copied to the new path parameter.
jsonSource.HeaderParameters.Add(new HeaderParameter("date", typeof(Expression), new Expression("?ReportDateParameter")));

Examples

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
};

Inheritance

See Also