Skip to content

Commit ca954e0

Browse files
committed
document options
1 parent 2bb6a05 commit ca954e0

File tree

5 files changed

+48
-192
lines changed

5 files changed

+48
-192
lines changed

couscous.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,7 @@ menu:
110110
relativeUrl: entityrepositories.html
111111
middleware:
112112
text: Middleware
113-
relativeUrl: middleware.html
113+
relativeUrl: middleware.html
114+
customqueryformat:
115+
text: Custom Query Formats
116+
relativeUrl: customqueryformat.html

docs/CustomQueryFormat.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
currentMenu: customqueryformat
3+
---
4+
5+
# Custom Query Formats
6+
7+
For information on the default query parameter formats, see the documentation for each query method.
8+
9+
In order to customize the query formats, you need to implement the `IQueryParser` interface and inject it like so:
10+
11+
```csharp
12+
services.AddScoped<IQueryParser, FooQueryParser>();
13+
```

docs/Options.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,32 @@ Accept: application/vnd.api+json
8080
}
8181
}
8282
}
83+
```
84+
85+
## Custom Query Parameters
86+
87+
If you would like to use custom query params (parameters not reserved by the json:api specification), you can set `AllowCustomQueryParameters = true`. The default behavior is to return an `HTTP 400 Bad Request` for unknown query parameters.
88+
89+
```csharp
90+
public IServiceProvider ConfigureServices(IServiceCollection services) {
91+
services.AddJsonApi<AppDbContext>(
92+
opt => opt.AllowCustomQueryParameters = true);
93+
// ...
94+
}
95+
```
96+
97+
## Custom Serializer Settings
98+
99+
We use Json.Net for all serialization needs. If you want to change the default serializer settings, you can:
100+
101+
```csharp
102+
public IServiceProvider ConfigureServices(IServiceCollection services) {
103+
services.AddJsonApi<AppDbContext>(
104+
opt => opt.SerializerSettings = new JsonSerializerSettings()
105+
{
106+
NullValueHandling = NullValueHandling.Ignore,
107+
ContractResolver = new DasherizedResolver()
108+
});
109+
// ...
110+
}
83111
```

docs/QueryingData.md

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

src/JsonApiDotNetCore/Controllers/HttpMethodRestrictionFilter.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
21
using System.Linq;
3-
using System.Reflection;
42
using System.Threading.Tasks;
5-
using JsonApiDotNetCore.Controllers;
63
using JsonApiDotNetCore.Internal;
74
using Microsoft.AspNetCore.Mvc.Filters;
85

@@ -17,15 +14,15 @@ public override async Task OnActionExecutionAsync(
1714
ActionExecutionDelegate next)
1815
{
1916
var method = context.HttpContext.Request.Method;
20-
21-
if(CanExecuteAction(method) == false)
17+
18+
if (CanExecuteAction(method) == false)
2219
throw new JsonApiException(405, $"This resource does not support {method} requests.");
2320

2421
await next();
2522
}
2623

2724
private bool CanExecuteAction(string requestMethod)
28-
{
25+
{
2926
return Methods.Contains(requestMethod) == false;
3027
}
3128
}

0 commit comments

Comments
 (0)