Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fable-import-fetch

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fable-import-fetch

Fable bindings for Fetch

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

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 -> // ...
}

Keywords

FAQs

Package last updated on 21 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc