Configuring Priority
Apizr could use Fusillade to offer some api priority management on calls.
To be short, Fusillade is about:
- Auto-deduplication of relevant requests
- Request Limiting
- Request Prioritization
- Speculative requests
Please refer to its official documentation if you’d like to know more about it.
Installing
Please first install this integration package:
Project | Current | Upcoming |
---|---|---|
Apizr.Integrations.Fusillade |
You can configure priority at:
- Design time by attribute decoration
- Register time by fluent configuration
- Request time by fluent configuration
The first thing to do while designing your api interfaces using Apizr to send a request, is to add an IApizrRequestOptions
param decorated with the provided RequestOptions
attribute to your methods like:
[BaseAddress("https://reqres.in/api")]
public interface IReqResService
{
[Get("/users")]
Task<UserList> GetUsersAsync([RequestOptions] IApizrRequestOptions options);
[Get("/users/{userId}")]
Task<UserDetails> GetUserAsync(int userId, [RequestOptions] IApizrRequestOptions options);
}
This way you'll make sure to pass your priority to the priority handler, defined thanks to request options builder at request time.
Another way to deal with priority at design time is to use the PriorityAttribute
:
[assembly:Priority(Priority.UserInitiated)]
namespace Your.Namespace
{
[BaseAddress("https://reqres.in/api"), Priority(Priority.Background)]
public interface IReqResService
{
[Get("/users"), Priority(Priority.Speculative)]
Task<UserList> GetUsersAsync([RequestOptions] IApizrRequestOptions options);
[Get("/users/{userId}")]
Task<UserDetails> GetUserAsync(int userId, [RequestOptions] IApizrRequestOptions options);
}
}
Here I'm saying:
- Send all requests of all apis with a default
UserInitiated
priority (the assembly one) - Excepted for all the requests of the
IReqResService
with aBackground
priority instead (the interface one) - Excepted for any GetUsersAsync request with a
Speculative
priority instead (the method one)
Of course, you could (should) mix it with the RequestOptions
method parameter implementation, so you could change your mind at request time with the request options builder.
Note that you can mix design, register and request time priority configurations. In case of mixed configurations, the internal duplicate strategy will be to take the closest one to the request.
Priority configuration duplicate strategy order:
- take fluent request configuration first if defined (request options)
- otherwise the request attribute decoration one (method)
- otherwise the fluent proper resgistration one (api proper options)
- otherwise the api attribute decoration one (interface)
- otherwise the fluent common resgistration one (registry common options)
- otherwise the global attribute decoration one (assembly)