# falcor-http-datasource

> This package contains falcor components for use in browsers.

Latest version **0.1.3** (published 2016-01-29) · ALV2 license · 0 weekly downloads

## Install

```sh
npm install falcor-http-datasource
pnpm add falcor-http-datasource
yarn add falcor-http-datasource
bun add falcor-http-datasource
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2016-01-29 |
| First published | 2015-08-17 |
| Weekly downloads | 0 |
| License | ALV2 |
| TypeScript types | separate (@types/falcor-http-datasource) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 56 |
| Author | Netflix |
| Maintainers | michael.paulson, netflix, satyend |
| Keywords | Falcor, Browser |

## Links

- npm: https://www.npmjs.com/package/falcor-http-datasource
- Repository: https://github.com/Netflix/falcor-http-datasource
- Issues: https://github.com/Netflix/falcor-http-datasource/issues
- npm.io page: https://npm.io/package/falcor-http-datasource

## Dependencies (1)

- [xmlhttprequest](https://npm.io/package/xmlhttprequest.md) ^1.7.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2016-01-29
- 0.1.2 — 2015-09-05
- 0.1.1 — 2015-08-17

## README

# HttpDataSource

This is a Falcor DataSource which can be used to retrieve JSON Graph information from an HTTP server.

## Install
```bash
npm install falcor-http-datasource
```

## Usage

Minimalistic ES6 example, a quick dirty setup

```es6
import falcor from 'falcor';
import HttpDataSource from 'falcor-http-datasource';
import user from 'app/models/user';

var model = new falcor.Model({
  source: new HttpDataSource('/model.json')
});
```
If you need some additional info for your global HTTP requests consider something like

JWT
```javascript
var source = new HttpDataSource('/model.json', {
  headers: {
    'Authorization': `bearer ' + token`
  }
});
```
Cookies
```javascript
var source = new HttpDataSource('/model.json', {
  withCredentials: true
});
// server must include the header `Access-Control-Allow-Credentials: true`
```
CORS
```javascript
var source = new HttpDataSource('/model.json', {
  crossDomain: true
});
```
or you might want to pass it to constructor as your global AppSource

```es6

export class AppSource extends HttpDataSource {
  constructor(path, token) {
    super(path, {
      headers: {
        'Authorization': `bearer ${ token }`
      }
      timeout: 20000
    })
  }

  get(...args) {
    // returns an Observable if you wanted to map/filter/reduce/etc
    return super.get(...args)
  }
  set(...args) {
    // returns an Observable if you wanted to map/filter/reduce/etc
    return super.set(...args)
  }
  call(...args) {
    // returns an Observable if you wanted to map/filter/reduce/etc
    return super.call(...args)
  }

  onBeforeRequest(config) {
    // as of now you're able to mutate the config object before we create our xhr instance
    // you would attach any url params here
    // config.url = config.url + '&something=Value'
    console.log(config);
  }
  buildQueryObject(...args) {
    // helper method to build our url for advanced implementations
    return super.buildQueryObject(...args)
  }
}

export class FalcorModel extends falcor.Model {
  constructor(cache) {
    super({
      cache: cache,
      source: new AppSource('/model.json', user.token)
    });
  }
}

```

---
_Source: https://npm.io/package/falcor-http-datasource · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
