@@ -137,7 +137,7 @@ var slidingWindowRateLimiter = _factory.GetSlidingWindowRateLimiter("key");
137137var tokenBucketRateLimiter = _factory .GetTokenBucketRateLimiter (" key" );
138138```
139139
140- ### Attrubutes
140+ ### Attrubutes for Grains
141141
142142You can use attributes to decorate your grain methods and apply rate limiting to them.
143143Make sure you check configuration section for default options.
@@ -168,6 +168,60 @@ public class TestFixedWindowRateLimiterGrain : Grain, ITestFixedWindowRateLimite
168168}
169169```
170170
171+ ### Attrubutes for WebAPI
172+
173+ You can define OrleansRateLimiterOptions with specific name.
174+ ``` cs
175+ builder .Services .AddOrleansRateLimiterOptions (" ip" , new FixedWindowRateLimiterOptions
176+ {
177+ QueueLimit = 5 ,
178+ PermitLimit = 10 ,
179+ Window = TimeSpan .FromSeconds (1 )
180+ });
181+
182+ builder .Services .AddOrleansRateLimiterOptions (" Anonymous" , new FixedWindowRateLimiterOptions
183+ {
184+ QueueLimit = 1 ,
185+ PermitLimit = 1 ,
186+ Window = TimeSpan .FromSeconds (1 )
187+ });
188+
189+ builder .Services .AddOrleansRateLimiterOptions (" Authorized" , new FixedWindowRateLimiterOptions
190+ {
191+ QueueLimit = 2 ,
192+ PermitLimit = 2 ,
193+ Window = TimeSpan .FromSeconds (1 )
194+ });
195+
196+ ```
197+
198+ then add middelware
199+ ``` cs
200+ app .UseOrleansIpRateLimiting (); // as earlier as possible
201+ .... .
202+ app .UseRouting ();
203+ app .UseCors ();
204+ app .MapControllers ();
205+
206+ // Authentication should always be placed before Authorization.
207+ app .UseAuthentication ();
208+ app .UseAuthorization ();
209+ app .UseOrleansUserRateLimiting (); // after Authorization and Authorization
210+ .... .
211+ ```
212+
213+ Finally you can add attributes to controller or single methods:
214+ ``` cs
215+ [AuthorizedIpRateLimiter (" Authorized" )]
216+ [AnonymousIpRateLimiter (" Authorized" )]
217+ [InRoleIpRateLimiter (" Authorized" , " Admin" )]
218+ [HttpGet (" get_some" )]
219+ public async Task < ActionResult < string >> GetSome ()
220+ {
221+ await Task .Delay (300 );
222+ return " OK" ;
223+ }
224+ ```
171225## Contributing
172226
173227We welcome contributions to Orleans.RateLimiting!
0 commit comments