0.7.5 • Published 10 years ago

fetched v0.7.5

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

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.

0.7.5

10 years ago

0.7.4

10 years ago

0.7.3

10 years ago

0.7.2

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago