Endpoint Configuration
Endpoint configuration determines which request path Flux.REST uses for each operation in a Set Context.
Configuration Precedence
When multiple configuration rules apply to a single endpoint, a rule with the most specific set of HTTP verbs and operational constraints will take precedence.
To demonstrate endpoint configuration precedence, suppose a school API uses separate paths for retrieving and managing students:
| HTTP method | Request path |
|---|---|
GET | /courses/{courseId}/students?offset={offset}&limit={limit} |
GET | /students/{id} |
POST | /management/students |
PUT | /management/students/{id} |
DELETE | /management/students/{id} |
Configure Flux
The Student Set has three endpoint configurations:
.AddSet<Student, int>()
.WithEndpoint("management/students")
.WithGet("students")
.WithGet((PageRequest _) => "courses/{{courseId}}/students")
WithGet("students")takes precedence overWithEndpoint("management/students")for the Get operation because it applies only toGETverb.WithGet((PageRequest _) => "courses/{courseId}/students")takes precedence overWithGet("students")because it applies specifically to the Get Page operation because of thePageRequestoperational constraint.WithEndpoint("management/students")specifies the base path, which is then used inAdd,Update, andRemoveoperations.
Tip
See the other available endpoint configuration method overloads.
Sample operations
Example operations that can be performed using the configuration as shown above:
| HTTP method | Request path | Configuration | Usage |
|---|---|---|---|
GET | /courses/{courseId}/students?offset={offset}&limit={limit} | .WithGet((PageRequest _) => "courses/{courseId}/students") | .GetPageAsync(offset: 0, limit: 20, parameters: parameters) |
GET | /students/{id} | .WithGet("students") | .GetAsync(42) |
POST | /management/students | .WithEndpoint("management/students") | .AddAsync(newStudent) |
PUT | /management/students/{id} | .WithEndpoint("management/students") | .UpdateAsync(updatedStudent, 42) |
DELETE | /management/students/{id} | .WithEndpoint("management/students") | .RemoveAsync(42) |