Home

Awesome

request

browser support

install

$ npm install bloody-request

require

var request = require("bloody-request")

api

var req = request.create(options || url)

Creates a new request, accepts params as an object, or a simple url string with the default params.

NOTE : a {"headerName":null} will cancel default headers.

var reqPromise = req.load()

Creates a XHR objects, and starts loading the target. Promise is fulfilled if 200 < status < 300 (or status = 304). Promise is rejected if status < 200 or if status status > 300 (not 304). The XHR object is passed as the value or the reason.

shorthands

events

returned promises have events you can listen to bloodyowl/promise

example

var request = require("bloody-request")

// if we are in a flux architecture
var AppDispatcher = require("../dispatcher")
var AppConstants = require("../constants")
var ActionTypes = AppConstants.ActionTypes

var API = {
  getTweets : function(){
    request.get(path.join(API_PATH, "tweets"))
      .then(
        function(xhr){
          AppDispatcher.handleServerAction({
            type : ActionTypes.RECEIVED_TWEETS_LIST,
            response : JSON.parse(xhr.responseText)
          })
        },
        function(xhr){
          AppDispatcher.handleServerAction({
            type : ActionTypes.DIDNT_RECEIVE_TWEETS_LIST,
            status : xhr.status
          })
        }
      )
  }
}

module.exports = API