PathParameter Class
A parameter that is used to add a path element to a JSON endpoint’s URI.
Namespace: DevExpress.DataAccess.Json
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
[TypeConverter(typeof(JsonDataSourceParameterTypeConverter<PathParameter>))]
public class PathParameter :
DataSourceParameterBase
Related API Members
The following members return PathParameter objects:
Remarks
Use path parameters to add path elements to a JSON endpoint’s Uri.
URI Example | Notes |
---|---|
http: //www.example.com/api/orders/startDate/2019-01-01/endDate/2019-12-31 | Use path parameters to specify the startDate and endDate. |
Add path parameters to PathParameterCollection and assign the collection to the UriJsonSource.PathParameters property.
The parameters are added to endpoint requests in the same order they occupy in PathParameterCollection. Change the order of elements in the collection to reposition parameters in endpoint requests.
Specify the following properties to configure a path parameter:
- Name - the parameter name.
- Type - the parameter type. Set it to the String to provide the parameter static value, or the Expression to specify an expression.
- Value - the parameter value.
You can use expressions to set the path parameter value. Specify an expression in the parameter’s Value property and specify that the parameter’s Type is Expression.
In DevExpress reports, expressions can include report parameters. Prepend the report parameter’s name with the ? character in an expression.
Note
The PathParameter
values are prepended to the resulting JSON Source URL unescaped. The System.Uri.EscapeUriString(String) method previously used internally is obsolete and no longer used. You can implement a custom function if you need escaping in PathParameter
values. For more information on custom functions refer to the following help topic: Custom Functions.
Example
The code sample below specifies a JSON endpoint and uses the date and id path parameters to identify the data record requested from the endpoint. The id path 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 "date" and "id" path parameters that are appended to the JSON URI: https://localhost:44367/api/values/date/2020-01-15/id/123/.
jsonSource.PathParameters.AddRange(new[] {
new PathParameter("date", typeof(String), String.Format("{0:yyyy-MM-dd}", DateTime.Today)),
// "ID" is a report parameter whose value is used for the "id" path parameter.
new PathParameter("id", typeof(Expression), new Expression("?ID"))
});
// Assign the JSON source to the data source.
var datasource = new JsonDataSource() {
JsonSource = jsonSource
};