Skip to content

Commit 10eb1e7

Browse files
committed
- update readme
1 parent 2a9e701 commit 10eb1e7

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

README.md

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
[![Nuget](https://img.shields.io/nuget/dt/ModEndpoints)](https://www.nuget.org/packages/ModEndpoints/)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/modabas/ModEndpoints/blob/main/LICENSE.txt)
66

7-
[WebResultEndpoints](#webresultendpoint), [BusinessResultEndpoints](#businessresultendpoint) and [ServiceEndpoints](#serviceendpoint) organize ASP.NET Core Minimal Apis in REPR format endpoints and are integrated with [result](https://github.com/modabas/ModResults) pattern out of box. They are implemented in ModEndpoints package.
7+
[MinimalEndpoints](#minimalendpoint) are the barebone implementation for organizing ASP.NET Core Minimal Apis in REPR format endpoints. Their handler methods may return Minimal Api IResult based, string or T (any other type) response. MinimalEnpoints are implemented in ModEndpoints.Core package.
88

9-
[MinimalEndpoints](#minimalendpoint) are the barebone implementation for organizing ASP.NET Core Minimal Apis in REPR format endpoints. They are not integrated with a result pattern like endpoints in ModEndpoints project and reside in ModEndpoints.Core package.
9+
[WebResultEndpoints](#webresultendpoint), [BusinessResultEndpoints](#businessresultendpoint) and [ServiceEndpoints](#serviceendpoint) organize ASP.NET Core Minimal Apis in REPR format endpoints and are integrated with [result](https://github.com/modabas/ModResults) pattern out of box. They are implemented in ModEndpoints package.
1010

11-
To make consuming a ServiceEndpoint easier, which is a very specialized endpoint more suitable for internal services, a specific [client implementation](#serviceendpoint-clients) along with extensions required for client registration is implemented in ModEndpoints.RemoteServices package, and interfaces required for ServiceEndpoint request models are in ModEndpoints.RemoteServices.Core package.
11+
To make consuming a [ServiceEndpoint](#serviceendpoint) easier, which is a very specialized endpoint more suitable for internal services, a specific [client implementation](#serviceendpoint-clients) along with extensions required for client registration is implemented in ModEndpoints.RemoteServices package, and interfaces required for ServiceEndpoint request models are in ModEndpoints.RemoteServices.Core package.
1212

1313
[ShowcaseWebApi](https://github.com/modabas/ModEndpoints/tree/main/samples/ShowcaseWebApi) project demonstrates various kinds of endpoint implementations and configurations. [Client](https://github.com/modabas/ModEndpoints/tree/main/samples/Client) project is a sample ServiceEndpoint consumer.
1414

@@ -23,7 +23,6 @@ All endpoint abstractions are a structured approach to defining endpoints in ASP
2323
- Has built-in validation support with [FluentValidation](https://github.com/FluentValidation/FluentValidation). If a validator is registered for request model, request is automatically validated before being handled.
2424
- Supports constructor dependency injection in endpoint implementations.
2525
- Enforces response model type safety in request handlers.
26-
- Abstracts the logic for converting business results into HTTP responses.
2726

2827
*WebResultEndpoint abstracts the logic for converting business results into HTTP responses.
2928

@@ -67,13 +66,53 @@ app.MapModEndpoints();
6766
app.Run();
6867
```
6968

70-
### A basic sample: A GET endpoint with empty request
69+
### Write a Minimal Api in REPR format
70+
71+
A [MinimalEndpoint](#minimalendpoint) is the most straighforward way to define a Minimal Api in REPR format.
7172

7273
Configuration of each endpoint implementation starts with calling one of the MapGet, MapPost, MapPut, MapDelete and MapPatch methods with a route pattern string. The return from any of these methods, a RouteHandlerBuilder instance, can be used to further customize the endpoint like a regular Minimal Api.
7374

74-
Have a look at [ShowcaseWebApi](https://github.com/modabas/ModEndpoints/tree/main/samples/ShowcaseWebApi) project for various kinds of endpoint implementations and configurations.
75+
The request is processed in 'HandleAsync' method. Request is passed to handler method as parameter after validation (if a validator is registered for request model). Handler method returns a response model or a string or a Minimal Api IResult based response.
76+
77+
``` csharp
78+
public record HelloWorldRequest(string Name);
79+
80+
internal class HelloWorldRequestValidator : AbstractValidator<HelloWorldRequest>
81+
{
82+
public HelloWorldRequestValidator()
83+
{
84+
RuleFor(x => x.Name)
85+
.NotEmpty()
86+
.MinimumLength(3)
87+
.MaximumLength(50);
88+
}
89+
}
7590

76-
This sample demonstrates a GET endpoint with basic configuration and without any request model binding.
91+
internal class HelloWorld
92+
: MinimalEndpoint<HelloWorldRequest, IResult>
93+
{
94+
protected override void Configure(
95+
IServiceProvider serviceProvider,
96+
IRouteGroupConfigurator? parentRouteGroup)
97+
{
98+
MapGet("MinimalEndpoints/HelloWorld/{Name}")
99+
.Produces<string>();
100+
}
101+
102+
protected override Task<IResult> HandleAsync(HelloWorldRequest req, CancellationToken ct)
103+
{
104+
return Task.FromResult(Results.Ok($"Hello, {req.Name}."));
105+
}
106+
}
107+
```
108+
109+
### Integration with result pattern: A GET WebResultEndpoint with empty request
110+
111+
A [WebResultEndpoint](#webresultendpoint) can be utilized to abstract the logic for converting business results into HTTP responses of endpoints. Configuration and request handling is similar to MinimalEndpoint, while a WebResultEndpoint handler method also has the benefit of having a strongly typed return while having potential to return different HTTP response codes according to business result state.
112+
113+
This sample demonstrates a GET endpoint with basic configuration and without any request model binding. Business result instance returned from handler method is converted to a Minimal Api IResult based response by WebResultEndpoint before being sent to client.
114+
115+
Have a look at [ShowcaseWebApi](https://github.com/modabas/ModEndpoints/tree/main/samples/ShowcaseWebApi) project for various kinds of endpoint implementations and configurations.
77116

78117
``` csharp
79118
public record ListBooksResponse(List<ListBooksResponseItem> Books);

0 commit comments

Comments
 (0)