How does one use HTTP Basic Authentication for requests in JsonProvider and infers types without a sample file?

StackOverflow https://stackoverflow.com/questions/21790462

Frage

This feels a n00b question, but I thought about trying the new FSharp.Data 2.0.0-alpha6 library on a project I have. Specifically I'm trying to read JSON messages from a web service that is protected by HTTP Basic Authentication (a username and a password).

How could one go with JsonProvider (or any other provider) to read documents from an URL that is procted by authorization, in this particular case by a HTTP Basic Authentication?

By judging the following SO questions it looks like I should download a sample file separately:

But then reading Gustavo's comment over at F# News: Downloading stock prices makes one hope it'd be possible.

Even if I had to download a sample file separately, how would I use the JsonProvider to parse the documents from resources that require HTTP Basic authentication?

My mininimal working sample is

open System
open FSharp.Data
open FSharp.Data.JsonExtensions

//The URLs are something like the following.
//https://xyz.com/rest/v1/datanodes?limit=20&expand=name,processData.v,processData.ts$format=json

//This one tells in a tooltip it cannot read sample from the address
//as server respons with an error 401 Unauthorized.
type x1 = JsonProvider<"https://xyz.com/rest/v1/datanodes?&format=json">

[<EntryPoint>]
let main argv = 

    //This is just of type object, probably because connection can't be made?
    let x2 = new JsonProvider<"https://xyz.com/rest/v1/datanodes?&format=json">

    0
War es hilfreich?

Lösung

It's not supported currently, but it should not be too difficult to implement, we accept pull requests. See https://github.com/fsharp/FSharp.Data/issues/158

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top