Skip to content

Commit d93c625

Browse files
committed
docs(readme): document the routing convention details
1 parent 06ec8a7 commit d93c625

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

JsonApiDotnetCore.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ EndProject
1515
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C5B4D998-CECB-454D-9F32-085A897577BE}"
1616
ProjectSection(SolutionItems) = preProject
1717
.gitignore = .gitignore
18+
README.md = README.md
1819
EndProjectSection
1920
EndProject
2021
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoEntityFrameworkExample", "src\NoEntityFrameworkExample\NoEntityFrameworkExample.csproj", "{570165EC-62B5-4684-A139-8D2A30DD4475}"

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,10 @@ services.AddJsonApi<AppDbContext>(
248248
#### Disable Convention
249249

250250
You can disable the dasherized convention and specify your own template
251-
by using the `DisableRoutingConvention` Attribute:
251+
by using the `DisableRoutingConvention` Attribute.
252252

253253
```csharp
254+
[Route("[controller]")]
254255
[DisableRoutingConvention]
255256
public class CamelCasedModelsController : JsonApiController<CamelCasedModel>
256257
{
@@ -263,6 +264,22 @@ public class CamelCasedModelsController : JsonApiController<CamelCasedModel>
263264
}
264265
```
265266

267+
It is important to note that your routes *must* still end with the model name in the same format
268+
as the resource name. This is so that we can build accurrate resource links in the json:api document.
269+
For example, if you define a resource as `MyModels` the controller route must match:
270+
271+
```csharp
272+
// resource definition
273+
builder.AddResource<TodoItem>("myModels");
274+
275+
// controller definition
276+
[Route("api/myModels")]
277+
[DisableRoutingConvention]
278+
public class TodoItemsController : JsonApiController<TodoItem>
279+
{ //...
280+
}
281+
```
282+
266283
### Defining Custom Data Access Methods
267284

268285
By default, data retrieval is distributed across 3 layers:
@@ -287,7 +304,7 @@ public void ConfigureServices(IServiceCollection services)
287304
services.AddJsonApi(options => {
288305
options.Namespace = "api/v1";
289306
options.BuildContextGraph((builder) => {
290-
builder.AddResource<MyModel>("my-models");
307+
builder.AddResource<MyModel>("my-models");1
291308
});
292309
}, mvcBuilder);
293310
// ...

src/JsonApiDotNetCoreExample/README.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)