Operation Parameters
Operation parameters can be used to supply values for path placeholders and query parameters.
The following examples assume that the Student Get Page endpoint configuration contains a {{courseId}} path placeholder:
.WithGet((PageRequest _) => "courses/{{courseId}}/students")
Configuration as shown above can be used as follows:
var parameters = new OperationParameterCollection(
new[]
{
new KeyValuePair<string, object>("courseId", 42),
new KeyValuePair<string, object>("order", "name"),
new KeyValuePair<string, object>("desc", true)
});
// /courses/42/students?order=name&desc=True&offset=0&limit=20
var studentsPage = await studentSetContext.GetPageAsync(
offset: 0,
limit: 20,
parameters: parameters);
Parameter names are case-sensitive and must match path placeholders exactly. A named parameter collection must provide a value for every placeholder in the path.
Query Parameters
By default, Flux.REST automatically adds the following query parameters:
- named operation parameters that are not matched to path placeholders;
- non-null
offsetandlimitparameters for the Get Page operation.
To control this behavior, use the queryComplete argument. When queryComplete is true, Flux.REST replaces path placeholders but does not append any query parameters.
For example, suppose the school API expects skip and take instead of offset and limit. Build the complete query string from the operation parameters and page request:
.WithGet((GetPageOperationDescriptor operation) =>
{
var namedParameters = (INamedOperationParameterCollection)operation.Parameters!;
var order = namedParameters.Values.First(x => x.Key == "order").Value;
var desc = namedParameters.Values.First(x => x.Key == "desc").Value;
var skip = operation.PageRequest.Offset;
var take = operation.PageRequest.Limit;
return $"courses/{{courseId}}/students?order={order}&desc={desc}&skip={skip}&take={take}";
},
queryComplete: true)
The Student Get Page operation now translates to the following URL path:
/courses/42/students?order=name&desc=True&skip=0&take=20