0.1.1 • Published 10 years ago
hqreq v0.1.1
HQReq - Library for making AJAX requests
Installation
Using npm:
$ npm install --save hqreqUsage
Import HttpRequest
ES6 modules
import {HttpRequest} from 'hqreq';Browserify
var HttpRequest = require('hqreq').HttpRequest;get
HttpRequest.get('/books')
.then(function (response) {
// get list of books in response
})
.catch(function () {
// Handle error response
});post
var book = {
// book fields go here
};
HttpRequest.post('/books', book)
.then(function (response) {
// get successful response after creating new book
})
.catch(function () {
// Handle error response
});put
var book = {
// book fields go here
};
HttpRequest.put('/books/123', book)
.then(function (response) {
// get successful response after updating existing book
})
.catch(function () {
// Handle error response
});delete
HttpRequest.delete('/books/123')
.then(function (response) {
// get successful response after deleting one book
})
.catch(function () {
// Handle error response
});patch
var book = {
// book fields go here
};
HttpRequest.patch('/books/123', book)
.then(function (response) {
// get successful response after updating specific parts of the book
})
.catch(function () {
// Handle error response
});trace
HttpRequest.trace('/books')
.then(function (response) {
// get successful response
})
.catch(function () {
// Handle error response
});options
HttpRequest.options('/books')
.then(function (response) {
// get successful response
})
.catch(function () {
// Handle error response
});head
HttpRequest.head('/books', book)
.then(function (response) {
// get successful response
})
.catch(function () {
// Handle error response
});