Skip to content

Solid.Http.Core Extending

Gísli Konráð Björnsson edited this page Jan 16, 2019 · 4 revisions

Extensions

SolidHttp is created with extensions and you can create your own quite easily.

Extension examples

Here are some examples on how to extend SolidHttpRequest. The first adds a function that adds a header with key "x-standard-header" and fixed text value "standard". The second example adds a function that adds a authorization header with a bearer token.

public static class StandardHeaderExtensions
{
    public static ISolidHttpRequest WithProprietaryHeader(this ISolidHttpRequest request)
    {
        return request.WithHeader("x-proprietary-header", "I am proprietary");
    }

    public static ISolidHttpRequest WithBearerToken(this ISolidHttpRequest request, string token)
    {
        return request.WithHeader("Authorization", $"Bearer {token}");
    }
}

ISolidHttpRequest is not the only useful thing to extend. Solid.Http.Core has multiple extensions classes where you can get some ideas on how to to create your own by looking them over.