Skip to content

Commit 4f40557

Browse files
authored
Update routing testing with a concrete example of calling an API route
1 parent b87fb11 commit 4f40557

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/apis/subsystems/routing/testing.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,19 @@ All of these methods also accept:
127127

128128
- any headers to provide with your request
129129
- any query parameters
130+
131+
As an example, to call the route `/api/rest/v2/question/bank/{course}/question_counts`, you would do the following:
132+
133+
```php title="Creating and processing a question_counts request"
134+
public function test_question_counts(): void {
135+
$this->resetAfterTest();
136+
$course = self::getDataGenerator()->create_course();
137+
138+
$this->add_class_routes_to_route_loader(
139+
\core_question\route\api::class,
140+
\core\router\route_loader_interface::ROUTE_GROUP_API, // This is implied for routes in an `api` namespace, but must be set for other route groups.
141+
);
142+
143+
$response = $this->process_api_request('GET', "/bank/{$course->id}/question_counts");
144+
}
145+
```

0 commit comments

Comments
 (0)