The Standard HTTP Driver for motorcycle.js based on superagent.
If you found an issue or want to contribute code, please read the contributing guidelines
Basics:
import most from 'most'
import {run} from '@motorcycle/core';
import {makeHTTPDriver} from '@motorcycle/http';
function main(sources) {
// ...
}
const sources = {
HTTP: makeHTTPDriver()
}
run(main, sources);
Simple and normal use case:
function main(sources) {
const HELLO_URL = 'http://localhost:8080/hello';
let request$ = most.just(HELLO_URL);
let vtree$ = sources.HTTP
.filter(res$ => res$.request === HELLO_URL)
.join()
.map(res => res.text) // We expect this to be "Hello World"
.startWith('Loading...')
.map(text =>
h('div.container', [
h('h1', text)
])
);
return {
DOM: vtree$,
HTTP: request$
};
}