From 4b883f6079d18f8f17df92bc12ea8a254e02c077 Mon Sep 17 00:00:00 2001 From: Aaron Contreras Date: Sat, 1 Apr 2017 05:05:17 +0200 Subject: [PATCH] Let superagent handle request body. Fix #55 --- src/adapters/superagent.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/adapters/superagent.js b/src/adapters/superagent.js index b7fc414f..fc981b62 100644 --- a/src/adapters/superagent.js +++ b/src/adapters/superagent.js @@ -1,29 +1,25 @@ import superagent from 'superagent'; import * as httpMethods from '../constants/http-methods'; -export const createRequest = (url, method) => { +export const createRequest = (url, method, body) => { switch (method) { case httpMethods.GET: - return superagent.get(url); + return superagent.get(url, body); case httpMethods.POST: - return superagent.post(url); + return superagent.post(url, body); case httpMethods.PUT: - return superagent.put(url); + return superagent.put(url, body); case httpMethods.PATCH: - return superagent.patch(url); + return superagent.patch(url, body); case httpMethods.DELETE: - return superagent.del(url); + return superagent.del(url, body); default: throw new Error(`Unsupported HTTP method: ${method}`); } }; const superagentNetworkAdapter = (url, method, { body, headers, credentials } = {}) => { - const request = createRequest(url, method); - - if (body) { - request.send(body); - } + const request = createRequest(url, method, body); if (headers) { request.set(headers);