Skip to content

Request authentication and interception

Jason Finch edited this page Aug 23, 2018 · 4 revisions

Client applications can customize HTTP requests generated by Simple.OData.Client in various ways. To achieve that you should pass to the initial Open method call an instance of ODataClientSettings instead of just a URL string. Here's the definition of ODataClientSettings class:

public class ODataClientSettings
{
    public Uri BaseUri { get; set; }
    public ICredentials Credentials { get; set; }
    public ODataPayloadFormat PayloadFormat { get; set; }
    public TimeSpan RequestTimeout { get; set; }
    public bool IncludeResourceTypeInEntryProperties { get; set; }
    public bool IgnoreResourceNotFoundException { get; set; }
    public bool IgnoreUnmappedProperties { get; set; }
    public string MetadataDocument { get; set; }

    public Func<HttpMessageHandler> OnCreateMessageHandler { get; set; }
    public Action<HttpClientHandler> OnApplyClientHandler { get; set; }
    public Action<HttpRequestMessage> BeforeRequest { get; set; }
    public Action<HttpResponseMessage> AfterResponse { get; set; }
    public Action<string, object[]> OnTrace { get; set; }

    // constructor overloads omitted
}

Using ODataClientSettings properties, it's possible to enable Basic and Windows authentication, override default behavior on 404 error code (instead of throwing an exception the adapter will return null), and even assign HTTP request or response interceptors.


See also:
Getting started with Simple.OData.Client