Skip to content

Commit 6936d2d

Browse files
authored
Improve documentation in README. (#10)
* Improve documentation in README. * PR feedback. * Fix spelling mistake in README.
1 parent 1ad8d66 commit 6936d2d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
[![NuGet version](https://img.shields.io/nuget/v/Winton.DomainModelling.AspNetCore.svg)](https://www.nuget.org/packages/Winton.DomainModelling.AspNetCore)
66
[![NuGet version](https://img.shields.io/nuget/vpre/Winton.DomainModelling.AspNetCore.svg)](https://www.nuget.org/packages/Winton.DomainModelling.AspNetCore)
77

8-
Conventions useful for creating an ASP.NET Core based REST API on top of a domain model.
8+
Conventions useful for creating an ASP.NET Core based REST API on top of a domain model. Specifically, it provides extension methods which convert from domain model types, as defined in [`Winton.DomainModelling.Abstractions`](https://github.com/wintoncode/Winton.DomainModelling.Abstractions) to ASP.NET Core types.
99

1010
## `Result` Extensions
1111

12-
This library provides a `ToActionResult` extension method for `Result<TData>` which converts it to an appropriate `IActionResult`.
13-
There are various overloads to provide flexibiility.
12+
`Result<TData>` is a type defined in the `Winton.DomainModelling.Abstractions` package.
13+
It is a type that is intended to be returned from domain operations.
14+
It allows operations to indicate both successes and failures to the client.
15+
In this case the client is an ASP.NET Core Controller.
16+
In a Controller, however, we need to return an `IActionResult` rather than a `Result<TData>`. We have two cases to consider:
17+
* If the `Result<TData>` was a success then we want to return a 2xx response from the API containing the data in the body.
18+
* If the `Result<TData>` was a failure then we want to return a 4xx response from the API containing [problem details](https://tools.ietf.org/html/rfc7807) in the body.
19+
20+
This library provides a `ToActionResult` extension method for `Result<TData>` which matches on the result and converts it to an appropriate `IActionResult`.
21+
There are various overloads to provide flexibility.
1422
It is expected that this will be used within an [`ApiController`](https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-2.2#annotation-with-apicontroller-attribute) so that ASP.NET Core will apply its REST API conventions to the `IActionResult`.
1523

1624
### Successful Result Mappings

0 commit comments

Comments
 (0)