Topic:   HOW TO Injecting params to all calls to RESTful Api?
Feb 12, 2021 10:46 2 Replies 99 Views KRISHNA SWAROOP

There are both ASP.Net Core & ASP.Net MVC5 sites that are calling restful services which all require two tokens for audit purposes: token1, token2. Here is an example of the

public interface ItemApi 
{
    GetItemResponse GetItem (int itemId, int token1, string token2);
}

The developer making the call should not be concerned with the values of token1/token2. While it is possible for the developer to always set them, the goal is to find a way to have the infrastructure set the values for the developer.

One idea is to introduce an interceptor to set the values before the actual call is made. After reading through all the documentation on Castle Windsor's Dynamic Proxy and Dora, it appears that the method the interceptor is working on must be annotated. Annotation is not an option because the interface is autogenerated from the OpenAPI Tool. Is there a way to use interceptors without annotations?

Is there any other way to insert params into each call to given RESTful services?

Prev Next
Topic Replies (2)
  1. 1
    idnkx user

    PARTH

    I assume the tokens are persisted somewhere in the client.
    You can simply create a HttpClient factory or simple utility that grabs the tokens from the persistent store.

    1
    idnkx user

    FRAUSKY

    It not clear how without annotations, an auto generated proxy could determine which parameters are token values. while you could create a signature mapping document, it seems it would be just as hard to produce as hand coding the proxy.
    public class proxy
    {
    private int _token1
    private string _token2
    private ItemApi;
    ...

    public GetItemResponse GetItem (int itemId) => ItemApi.GetItem (itemId, _token1, _token2);
    ...
    }

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect