0.2.4 • Published 9 years ago

fable-import-fetch v0.2.4

Weekly downloads
19
License
Apache-2.0
Repository
github
Last release
9 years ago

fable-import-fetch

Fable bindings for Fetch API

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

See: https://developer.mozilla.org/en/docs/Web/API/Fetch_API

Installation

$ npm install --save fable-core
$ npm install --save-dev fable-import-fetch

Usage

In a F# project (.fsproj)

  <ItemGroup>
    <Reference Include="node_modules/fable-core/Fable.Core.dll" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="node_modules/fable-import-fetch/Fable.Import.Fetch.fs" />
    <Compile Include="node_modules/fable-import-fetch/Fable.Helpers.Fetch.fs" />
  </ItemGroup>

In a F# script (.fsx)

#r "node_modules/fable-core/Fable.Core.dll"
#load "node_modules/fable-import-fetch/Fable.Import.Fetch.fs"
#load "node_modules/fable-import-fetch/Fable.Helpers.Fetch.fs"

Using Fetch from F

open Fable.Core
open Fable.Import.Fetch
open Fable.Helpers.Fetch

// getting data and parsing from JSON
async { 
    try 
        let! records = fetchAs<MyRecord[]>("http://www.server.com/data.json" , [])
        // ...
    with
    | error -> ...
} 

// posting data to a server
async { 
    let! response = postRecord(
                      "http://www.server.com/data.json", 
                      myRecord,
                      [ RequestProperties.Headers [ 
                          HttpRequestHeaders.Accept "application/xml" ]
                      ])

    if response.ok then
        match response.Headers.ContentType with
        | None -> // ...
        | Some contentType -> // ...
}
0.2.4

9 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago