fetchface
Advanced tools
Comparing version 1.0.5 to 1.0.6
25
index.js
@@ -1,7 +0,6 @@ | ||
const defaultHeaders = { 'Content-Type': 'application/json' }; | ||
// eslint-disable-next-line no-var | ||
var defaultHeaders = { 'Content-Type': 'application/json' }; | ||
var globalHeaders = Object.assign({}, defaultHeaders); | ||
// Allow for response code hooks | ||
const responseCodeCallbacks = {}; | ||
var responseCodeCallbacks = {}; | ||
@@ -50,3 +49,2 @@ function handleResponse(resolve, reject, response) { | ||
// Base headers | ||
// eslint-disable-next-line no-var | ||
var localHeaders = Object.assign({}, globalHeaders); | ||
@@ -88,3 +86,3 @@ | ||
// Handling body based on type (FormData vs. JSON) | ||
const isFormData = body instanceof FormData; // eslint-disable-line | ||
var isFormData = body instanceof FormData; | ||
if (isFormData) { | ||
@@ -116,6 +114,14 @@ // Let the browser deal with Content-Type header when using FormData | ||
function post(url, config) { postPutDelete('POST', url, config); } | ||
function put(url, config) { postPutDelete('PUT', url, config); } | ||
function del(url, config) { postPutDelete('DELETE', url, config); } | ||
function post(url, config) { | ||
return postPutDelete('POST', url, config); | ||
} | ||
function put(url, config) { | ||
return postPutDelete('PUT', url, config); | ||
} | ||
function del(url, config) { | ||
return postPutDelete('DELETE', url, config); | ||
} | ||
// Set global headers | ||
@@ -131,4 +137,3 @@ function setHeaders(newHeaders) { | ||
// Allow for callback "hooks" based on API response codes. | ||
// For example, onResponseCode(404, () => { alert('Resource not found.') }) | ||
// Allow for callback hooks based on server response codes | ||
function onResponseCode(code, callback) { | ||
@@ -135,0 +140,0 @@ responseCodeCallbacks[code] = callback; |
{ | ||
"name": "fetchface", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A convenient interface for the Fetch API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
123
8091