Skip to content

Commit

Permalink
Let superagent handle request body. Fix #55
Browse files Browse the repository at this point in the history
  • Loading branch information
acontreras89 committed Apr 1, 2017
1 parent 3a26bb4 commit 4b883f6
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/adapters/superagent.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 4b883f6

Please sign in to comment.