You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage/routing.md
+50-29Lines changed: 50 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,55 @@
1
1
# Routing
2
-
3
-
By default the library will configure routes for each controller.
4
-
Based on the [recommendations](https://jsonapi.org/recommendations/) outlined in the json:api spec, routes are camel-cased.
2
+
The library will configure routes for each controller. By default, based on the [recommendations](https://jsonapi.org/recommendations/) outlined in the json:api spec, routes are camel-cased.
5
3
6
4
```http
7
5
GET /api/compoundModels HTTP/1.1
8
6
```
9
7
10
-
## Namespacing and Versioning URLs
8
+
There are two ways the library will try to create a route for a controller:
9
+
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.
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.
It is possible to fully customize routing behaviour by registering a `IJsonApiRoutingConvention` implementation **before** calling `AddJsonApi( ... )`.
You can add a namespace to all URLs by specifying it in ConfigureServices
13
54
14
55
```c#
@@ -20,40 +61,20 @@ public void ConfigureServices(IServiceCollection services)
20
61
```
21
62
Which results in URLs like: https://yourdomain.com/api/v1/people
22
63
23
-
## Disable Convention
24
-
25
-
You can disable the default casing convention and specify your own template by using the `DisableRoutingConvention` attribute.
64
+
## Disabling the Default Routing Convention
65
+
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).
It is important to note that your routes must still end with the model name in the same format as the resource name. This is so that we can build accurate resource links in the json:api document. For example, if you define a resource as MyModels, the controller route must match.
0 commit comments