Modifying invisible API method codes

44 Views Asked by At

I am using invisible API library in asp.net, and I should call all API endpoints inside this invisible API configuration, in documentation written like this:

app.UseInvisibleApis(new List<InvisibleApiConfiguration>
        {
            new InvisibleApiConfiguration
            {
                Endpoint = "/api/home",
                Header = "Hush",
                Value = "I'm a good guy",
                HttpVerb = "GET"
            }
        });

This just for one API endpoint, how can I add multiple endpoints, if I write all of them like this, codes becoming huge. And also can I also add multiple http methods?

I write this method:

private static InvisibleApiConfiguration CreateInvisibleApiConfiguration(
        string endpoint, string httpVerb, string header, string value)
    {
        return new InvisibleApiConfiguration
        {
            Endpoint = endpoint,
            HttpVerb = httpVerb,
            Header = header,
            Value = value
        };
    }

and call this inside configuration to make code lines smaller, but not help:

CreateInvisibleApiConfiguration("/api/Scores", "POST",
            "SecretHeaderScores", "SecretValueScores"),
        CreateInvisibleApiConfiguration("/api/Scores", "GET",
            "SecretHeaderScores", "SecretValueScores"),
        CreateInvisibleApiConfiguration("/api/Scores", "PUT",
            "SecretHeaderScores", "SecretValueScores"),
        CreateInvisibleApiConfiguration("/api/Scores", "DELETE",
            "SecretHeaderScores", "SecretValueScores"),

like this lines become huge.

0

There are 0 best solutions below