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

fetched

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetched

A xhr request formatter (window.fetch) with an ajax/superagent inspired API

  • 0.7.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

fetched

npm Build Status

fetched provides a declarative wrapper for request parameters. It's targeted towards window.fetch standard, but can be used to format request object for other XMLHttpRequest libraries

In general, fetched is a xhr request formatter with an ajax/superagent inspired API that is targeted toward window.fetch WHATWG standard / polyfill.

Installation

npm install fetched --save

To use fetch, You may need the following polyfills:

fetch npm install whatwg-fetch --save

promise npm install es6-promise --save

Usage

For example, posting data to http://example.com/api/me

import Fetched from 'fetched';

let agent = new Fetched('http://localhost');

agent.post('/api/me')
    .send({
        username: 'my-username',
        password: 'my-password'
    })
    .json()
    .withCredentials()
    .using(fetch); // uses window.fetch object. Can be other compatible HTTP request libraries.

The above will return a fetch promise object.

To use with other libraries, you can do the following:

let result = agent.post('/api/me')
    .send({
        username: 'my-username',
        password: 'my-password'
    })
    .json()
    .withCredentials()
    .format();

You should get the following output in your result variable:

{
    "resource": "http://localhost",
    "params": {
        "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json"
        },
        "method": "post",
        "body": "{'username':'my-username','password':'my-password'}",
        "credentials": "include"
    }
}

Note:

API is still a little unstable.

Keywords

FAQs

Package last updated on 13 Sep 2015

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