Skip to content

Commit d91bf76

Browse files
committed
Update routing.md
Rephrasing
1 parent 9d90952 commit d91bf76

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

docs/usage/routing.md

+7-17
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ GET /api/compoundModels HTTP/1.1
77

88
There are two ways the library will try to create a route for a controller:
99
1. **By inspecting the controller for an associated resource**. The library will try to first use the public resource name of the resource associated to a controller. This means that the value of the `type` member of the json:api document for a resource will be equal to the route.
10-
Note that this implies that it is possible to configure a route configuring the exposed resource name. See [this section](~/usage/resource-graph.md#public-resource-name) on how this can be achieved.
11-
For example:
10+
Note that this implies that it is possible to configure a route configuring the exposed resource name. See [this section](~/usage/resource-graph.md#public-resource-name) on how this can be achieved. Example:
1211
```c#
1312
// controller
14-
public class MyResourceController : JsonApiController<MyApiResource> { /* .... */ }
13+
public class MyResourceController : JsonApiController<MyApiResource> { /* .... */ } // note that the route is NOT "myResources", but "myApiResources"
1514
1615
// request
1716
GET /myApiResources HTTP/1.1
@@ -28,8 +27,8 @@ Content-Type: application/vnd.api+json
2827
}]
2928
}
3029
```
31-
2. **By using the name of the controller**. If no associated resource was detected for a controller, the library will construct a route from the name of the controller by using the configured naming strategy (*camelCase* by default, see [this section](~/usage/resource-graph.md#public-resource-name) on how to configure this).
32-
In the following example the controller does not inherit from `BaseJsonApiController<T>` and the library is unable associate a resource to it.
30+
2. **By using the name of the controller**. If no associated resource was detected for a controller, the library will construct a route from the name of the controller by using the configured naming strategy (*camelCase* by default, see [this section](~/usage/resource-graph.md#public-resource-name) on how to configure this). This is in alignment with the default .NET Core MVC routing approach.
31+
In the following example the controller is not associated to a resource by the library because it does not inherit from `BaseJsonApiController<T>`.
3332
```c#
3433
// controller
3534
public class MyResourceController : ControllerBase { /* .... */ }
@@ -63,18 +62,9 @@ Which results in URLs like: https://yourdomain.com/api/v1/people
6362

6463
## Disabling the Default Routing Convention
6564
It is possible to completely bypass the default routing convention for a particular controller and specify a custom routing template by using the `DisableRoutingConvention` attribute.
66-
In the following example, the `CamelCasedModel` resource can be accessed on `/myCustomResources` (assuming that the default naming strategy is used).
65+
In the following example, the `CamelCasedModel` resource can be accessed on `/myCustomResources` (this assumes that the default naming strategy is unchanged).
6766

6867
```c#
69-
[Route("[controller]")]
70-
[DisableRoutingConvention]
71-
public class MyCustomResourceController : JsonApiController<CamelCasedModel>
72-
{
73-
public MyCustomResourceController(
74-
IJsonApiOptions jsonApiOptions,
75-
ILoggerFactory loggerFactory,
76-
IResourceService<CamelCasedModel> resourceService)
77-
: base(jsonApiOptions, loggerFactory, resourceService)
78-
{ }
79-
}
68+
[Route("[controller]"), DisableRoutingConvention]
69+
public class MyCustomResourceController : JsonApiController<CamelCasedModel> { /* ... */ }
8070
```

0 commit comments

Comments
 (0)