You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-88Lines changed: 44 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,17 +81,20 @@ if (app.Environment.IsDevelopment())
81
81
82
82
app.Run();
83
83
```
84
+
**See *[program.cs](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Program.cs)* in sample project**
Adds the WebApiEndpoints to the pipeline and does various other setup needed for the WebApiEndpoints to work.
95
98
```csharp
96
99
app.UseWebApiEndpoints();
97
100
```
@@ -102,21 +105,21 @@ Register the OpenApi UI (Swagger and SwaggerUI) middleware. This is usually only
102
105
app.UseWebApiEndpointsOpenApi();
103
106
```
104
107
105
-
### WebApiEndpoint
106
-
1. Create a new partial class
107
-
2. Add the *WebApiEndpoint* attribute to the class, with the *route prefix*and optionally a *tag*
108
-
3. Add the *WebApiEndpointVersion* attribute to the class, if you want to specify a specific *ApiVersion*
109
-
4. Implement the *Build* method and add *minimal api(s)* as per usual
108
+
### How to create a WebApiEndpoint
109
+
1. Create a new partial class.
110
+
2. Add the *WebApiEndpoint* attribute to the class, with the *route prefix*for all the REST methods in this WebApiEndpoint. You can also optionally add a *tag*. This is used in the OpenApi documentation. If you do not specify a tag, then the route prefix is used.
111
+
3. Add the *WebApiEndpointVersion* attribute to the class, if you want to specify a specific *ApiVersion*. If you do not specify a specific *ApiVersion*, then the default *ApiVersion* is used. You can add multiple *WebApiEndpointVersion* attributes to the class, if you want to support multiple *ApiVersions*.
112
+
4. Implement the *Build* method and add *minimal api(s)* as per usual.
110
113
5.*Optionally* implement the *Configure* method to configuration the *WebApiEndpoint*
111
114
112
115
#### Build
113
116
You can *map* your minimal apis for this WebApiEndpoint in the *Build* method.
114
117
115
-
The *IEndpointRouteBuilder*parameter is already:
116
-
- configured with [configuring for the entire API](#configuring-the-entire-api)
117
-
- configured with the API versioning
118
-
- configured with [configuring a specific API version](#configuring-a-specific-api-version)
119
-
- configured with the route prefix and tag
118
+
The *IEndpointRouteBuilder*that the *Build* method receives has already:
119
+
-been configured with [configuring for the entire API](#configuring-the-entire-api)
120
+
-been configured with the API versioning
121
+
-been configured with [configuring a specific API version](#configuring-a-specific-api-version)
122
+
-been configured with the route prefix and tag
120
123
- been through the *optional**[Configure](#configure)* method in the same class
@@ -147,104 +149,55 @@ public partial class WeatherWebApiEndpoint
147
149
.ToOk();
148
150
}
149
151
```
152
+
**See *[WeatherWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/WeatherForecast/WeatherWebApiEndpoint.cs)* in sample project**
**See *[EndpointFilterWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Features/EndpointFilterWebApiEndpoint.cs)* in sample project**
172
+
173
+
#### This ia a good place to add a WebApiEndpoint specific *RateLimiting*
**See *[RateLimitingWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Features/RateLimitingWebApiEndpoint.cs)* in sample project**
178
+
179
+
#### This ia a good place to add a WebApiEndpoint specific *OutputCache*
**See *[OutputCachingWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Features/OutputCachingWebApiEndpoint.cs)* in sample project**
232
184
233
-
#### This ia a good place to add *Security*
185
+
#### This ia a good place to add WebApiEndpoint specific *Security*
**See *[SecurityProtectedWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Security/SecurityProtectedWebApiEndpoint.cs)* in sample project**
237
190
238
-
## Configure
191
+
## Configuration
239
192
### Configuring Futurum.WebApiEndpoint.Micro
240
-
Allows you to configure:
193
+
This allows you to configure:
241
194
- DefaultApiVersion *(mandatory)*
242
-
- This is used if a specific ApiVersion is not provided for a specific WebApiEndpoint
195
+
- This is used if a ApiVersion is not provided for a specific WebApiEndpoint.
243
196
- OpenApi
244
197
- DefaultInfo *(optional)*
245
-
- This is used if a specific OpenApiInfo is not provided for a specific ApiVersion
198
+
- This is used if a OpenApiInfo is not provided for a specific ApiVersion
246
199
- VersionedInfo *(optional)*
247
-
- Allowing you to have different OpenApiInfo per ApiVersion
200
+
- Allowing you to have an OpenApiInfo per a specific ApiVersion. If you do not provide an OpenApiInfo for a specific ApiVersion, then the DefaultInfo is used.
248
201
- Version
249
202
- Prefix *(optional)*
250
203
- Format *(optional)*
@@ -274,6 +227,7 @@ builder.Services
274
227
}
275
228
});
276
229
```
230
+
**See *[program.cs](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/Program.cs)* in sample project**
277
231
278
232
### Configuring the entire API
279
233
The entire API can be configured. This is a good place to configure things like:
@@ -282,7 +236,7 @@ The entire API can be configured. This is a good place to configure things like:
282
236
283
237
The class must implement *IGlobalWebApiEndpoint* interface
284
238
285
-
** NOTE - there can only be one of these classes. **
239
+
** NOTE - there can only be one of these classes. There is an [analyser](#roslyn-analysers) to check for this. **
286
240
287
241
** NOTE - this is applied before the version route is created. **
288
242
@@ -296,16 +250,17 @@ public class GlobalWebApiEndpoint : IGlobalWebApiEndpoint
296
250
}
297
251
}
298
252
```
253
+
**See *[GlobalWebApiEndpoint](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/GlobalWebApiEndpoint.cs)* in sample project**
299
254
300
255
### Configuring a specific API version
301
256
A specific API version can be configured. This is a good place to configure things like:
302
257
- API version specific authorization (don't forget to set *AllowAnonymous* on the individual WebApiEndpoint that you don't want to be secured i.e. *Login* endpoint)
303
258
304
259
The class must:
305
260
- implement *IWebApiVersionEndpoint* interface
306
-
- be decorated with at least one *WebApiVersionEndpointVersion* attribute
261
+
- be decorated with at least one *WebApiVersionEndpointVersion* attribute, for the version(s) it applies to
307
262
308
-
** NOTE - there can only be one of these classes per version. **
263
+
** NOTE - there can only be one of these classes per version. There is an [analyser](#roslyn-analysers) to check for this. **
309
264
310
265
** NOTE - this is applied after the version route is created, but before the WebApiEndpoint specific route is created. **
311
266
@@ -320,6 +275,7 @@ public class WebApiVersionEndpoint3_0 : IWebApiVersionEndpoint
320
275
}
321
276
}
322
277
```
278
+
**See *[WebApiVersionEndpoint3_0a](https://github.com/futurum-dev/dotnet.futurum.webapiendpoint.micro/blob/main/sample/Futurum.WebApiEndpoint.Micro.Sample/WebApiVersionEndpoint3_0.cs)* in sample project**
323
279
324
280
## Sandbox runner
325
281
### Run and RunAsync - If your code returns an *IResult*
0 commit comments