Skip to content

docs(options) #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ menu:
relativeUrl: entityrepositories.html
middleware:
text: Middleware
relativeUrl: middleware.html
relativeUrl: middleware.html
customqueryformat:
text: Custom Query Formats
relativeUrl: customqueryformat.html
13 changes: 13 additions & 0 deletions docs/CustomQueryFormat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
currentMenu: customqueryformat
---

# Custom Query Formats

For information on the default query parameter formats, see the documentation for each query method.

In order to customize the query formats, you need to implement the `IQueryParser` interface and inject it like so:

```csharp
services.AddScoped<IQueryParser, FooQueryParser>();
```
28 changes: 28 additions & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,32 @@ Accept: application/vnd.api+json
}
}
}
```

## Custom Query Parameters

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.

```csharp
public IServiceProvider ConfigureServices(IServiceCollection services) {
services.AddJsonApi<AppDbContext>(
opt => opt.AllowCustomQueryParameters = true);
// ...
}
```

## Custom Serializer Settings

We use Json.Net for all serialization needs. If you want to change the default serializer settings, you can:

```csharp
public IServiceProvider ConfigureServices(IServiceCollection services) {
services.AddJsonApi<AppDbContext>(
opt => opt.SerializerSettings = new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new DasherizedResolver()
});
// ...
}
```
185 changes: 0 additions & 185 deletions docs/QueryingData.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using JsonApiDotNetCore.Controllers;
using JsonApiDotNetCore.Internal;
using Microsoft.AspNetCore.Mvc.Filters;

Expand All @@ -17,15 +14,15 @@ public override async Task OnActionExecutionAsync(
ActionExecutionDelegate next)
{
var method = context.HttpContext.Request.Method;
if(CanExecuteAction(method) == false)

if (CanExecuteAction(method) == false)
throw new JsonApiException(405, $"This resource does not support {method} requests.");

await next();
}

private bool CanExecuteAction(string requestMethod)
{
{
return Methods.Contains(requestMethod) == false;
}
}
Expand Down