Code Monkey home page Code Monkey logo

fable-fetch's People

Contributors

alfonsogarciacaro avatar angelmunoz avatar bebersdocks avatar darkle avatar delneg avatar dependabot[bot] avatar mangelmaxime avatar uxsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fable-fetch's Issues

Add signal to RequestProperties

I wanted to be able to abort fetches while using these bindings but realised it doesn't have support for the signal property. I made a start at implementing it however I realised its AbortController hasn't been implemented in Node.js as far as I can tell so isn't possible to test it. Does this browser specific binding belong in this library or are you trying to keep it as generic as possible? If it doesn't belong here what would be a good approach to making it available to use?

https://developer.mozilla.org/en-US/docs/Web/API/AbortController

Add FetchAs with latest Thoth.Json

Fetch tests
√ fetch: requests work (89ms)
√ fetch: parallel requests work (176ms)
√ fetch: unsuccessful HTTP status codes throw an error
√ tryFetch: unsuccessful HTTP status codes returns an Error
√ tryFetch: Successful HTTP OPTIONS request (1689ms)
√ tryFetch: Failed HTTP OPTIONS request on Fable.io server
√ tryFetch: exceptions return an Error
√ tryOptionsRequest: Successful HTTP OPTIONS request (1522ms)
√ tryOptionsRequest: Failed HTTP OPTIONS request on Fable.io server
√ fetchAs: works with manual decoder (393ms)
√ fetchAs: fails if the decoder fail (659ms)
√ fetchAs: works with auto decoder (384ms)
√ fetchAs: fails if the auto decoder fail (377ms)
√ tryFetchAs: works with manual decoder (474ms)
√ tryFetchAs: fails if the decoder fail (687ms)
√ tryFetchAs: works with auto decoder (151ms)
√ tryFetchAs: fails if the auto decoder fail (130ms)

17 passing (7s)

Form data support

Hi, I noticed that form data support was commented out in one of the beta commits. Do you have any plans on putting it back in? Any recommendations what to use instead when you need to support form data?

Add samples and documentation

It is very hard to find documentation for Fable which negatively affects adopting it. Please add how-to guides for basic things like Fetch/Ajax.

Uncaught (in promise) Error: 0 for URL

Fetch.fs?8131:379 Uncaught (in promise) Error: 0 for URL
at a (Fetch.fs?8131:379)

When I try to run function (based on sample from Fable):

 let getAutoComplete (state: State) = 
            let url = match state.FromBase with
                        | true -> sprintf "%s/api/v1/base_terms/?text=%s&translation_language_id=%i&page=1&per_page=5"
                                            Domain state.SearchText state.CurrentLanguage.Value.id
                        | false -> sprintf "%s/api/v1/translations/?text=%s&base_term_language_id=%i&page=1&per_page=5&current=true"
                                            Domain state.SearchText state.CurrentBaseLanguage.Value.id

            fetch url [Types.RequestProperties.Mode Types.RequestMode.Nocors] // use the fetch api to load our resource
               
               |> Promise.bind (fun res -> res.text()) // get the resul
               |> Promise.map (fun txt -> // bind the result to make further operation
                    printfn "Woof! Woof! %s" txt
                    let decoded = Decode.Auto.fromString<Page<ResultTranslation>> (txt, true)
                    match decoded with
                    | Ok translationPage ->  // everything went well! great!
                        let actualDogURL = translationPage.pages
                        printfn "Woof! Woof! %i" actualDogURL
                    | Error decodingError -> // oh the decoder encountered an error. The string that was sent back from our fetch request does not map well to our PictureInfo type.
                        failwith (sprintf "was unable to decode: %s. Reason: %s" txt decodingError)
                )

Proper URL is: https://slownik-oriin.kropleduszy.pl:8000/api/v1/base_terms/?text=&translation_language_id=1&page=1&per_page=5

Whole code:

namespace OrinDic
open Feliz
open Elmish
open OrinDic.Models
open Fable.Core.JsInterop
open Fable.Import
open Fetch
open Thoth.Json

    module App =

        

        type State = { 
            SearchText : string
            SearchPage : int
            ItemsPerPage : int
            MaxSearchPage : int
            SearchResultsCount : int
            CurrentLanguage : Language option
            CurrentBaseLanguage : Language option
            Languages : Language list
            BaseLanguages : Language list
            Users : obj list
            Translations : Translation list
            TranslationPage : bool
            TranslationsPage : Page<ResultTranslation> option
            Loading : bool
            FromBase : bool
            ShowKeyboard : bool
            AutoCompletes : ResultTranslation list
            }

        type Msg =
            | Increment
            | Decrement

        let [<Literal>] Domain = "https://slownik-oriin.kropleduszy.pl:8000"   

        let init() = 
            let plLanguage = {
                           id = 1
                           name = "Polski"
                           code="PL"
                           special_characters = []}

            { 
               SearchText =  ""
               SearchPage = 1
               ItemsPerPage = 100
               MaxSearchPage = 0
               SearchResultsCount = 0
               CurrentLanguage = Some plLanguage
               CurrentBaseLanguage = Some plLanguage
               Languages = []
               BaseLanguages = []
               Users = []
               Translations = []
               TranslationPage = false
               TranslationsPage = None
               Loading = true
               FromBase = true
               ShowKeyboard = false
               AutoCompletes = []
            }, Cmd.none



        let getAutoComplete (state: State) = 
            let url = match state.FromBase with
                        | true -> sprintf "%s/api/v1/base_terms/?text=%s&translation_language_id=%i&page=1&per_page=5"
                                            Domain state.SearchText state.CurrentLanguage.Value.id
                        | false -> sprintf "%s/api/v1/translations/?text=%s&base_term_language_id=%i&page=1&per_page=5&current=true"
                                            Domain state.SearchText state.CurrentBaseLanguage.Value.id

            fetch url [Types.RequestProperties.Mode Types.RequestMode.Nocors] // use the fetch api to load our resource
               
               |> Promise.bind (fun res -> res.text()) // get the resul
               |> Promise.map (fun txt -> // bind the result to make further operation
                    printfn "Woof! Woof! %s" txt
                    let decoded = Decode.Auto.fromString<Page<ResultTranslation>> (txt, true)
                    match decoded with
                    | Ok translationPage ->  // everything went well! great!
                        let actualDogURL = translationPage.pages
                        printfn "Woof! Woof! %i" actualDogURL
                    | Error decodingError -> // oh the decoder encountered an error. The string that was sent back from our fetch request does not map well to our PictureInfo type.
                        failwith (sprintf "was unable to decode: %s. Reason: %s" txt decodingError)
                )
            

        let update (msg: Msg) (state: State) =
            match msg with
            | Increment -> 
                let a = getAutoComplete state
                { state with SearchPage = state.SearchPage + 1 }, Cmd.none
            | Decrement -> { state with SearchPage = state.SearchPage - 1 }, Cmd.none

        let render (state: State) (dispatch: Msg -> unit) =
            Html.div [
                Html.button [
                    prop.onClick (fun _ -> dispatch Increment)
                    prop.text "Increment me"
                ]

                Html.button [
                    prop.onClick (fun _ -> dispatch Decrement)
                    prop.text "Decrement"
                ]

                Html.h1 state.SearchPage
            ]

namespace OrinDic

    module Models =

        type public BaseTerm =
            {
                id : int
                language_id : int
                slug : string
                name : string
                synonyms : obj list
                definition : string
                last_edit_id : int
            }


        type public Translation =
            {
                id : int
                base_term_id : int
                language_id : int
                current : bool
                name : string
                synonyms : obj list
                definition : string
                last_edit_id : int
                last_approval_id : obj
            }

        type public ResultTranslation =
            {
                base_term : BaseTerm
                translation : Translation
            }

         type public Language = 
             {
                 id : int
                 name : string
                 code : string
                 special_characters : char list
             }
         

        type public Page<'a> =
            {
               pages : int
               count : int
               current_page : int
               results : 'a list
            }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.