Martin Thompson
Martin Thompson

Reputation: 3755

Unable to Authenticate REST Api using F# and RestSharp for Mailgun

I'm tring to use restsharp in F# to call the Mailgun API.

I modelled it on the sample C# code from Mailgun but I can't get it going.

The problem code is:

    let client: RestClient = 
        new RestClient(
            BaseUrl = Uri("https://api.mailgun.net/v3")
        )
        
    client.Authenticator = new HttpBasicAuthenticator("","") 

This expression was expected to have type IAuthenticator' but here has type 'HttpBasicAuthenticator'

It seems that somehow the inherited type for one is different than the expected type which doesn't make sense to me. The HttpBasicAuthenticator object says it inherits from authentocatorBase

Upvotes: 0

Views: 208

Answers (1)

Piotr Rodak
Piotr Rodak

Reputation: 1941

I haven't tested it, but most likely you have to cast the new object to the interface. F# requires it.

client.Authenticator = new HttpBasicAuthenticator("","") :> IAuthenticator

Have a look at https://fsharpforfunandprofit.com/posts/interfaces/

Upvotes: 1

Related Questions