Skip to content

Commit

Permalink
fix: pass parsed options into request
Browse files Browse the repository at this point in the history
this should be a refactor but @ocotkit/rest uses these internals
  • Loading branch information
gr2m committed Oct 31, 2018
1 parent 555b831 commit f57f14a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const mockable = require('./fetch')
const getBuffer = require('./get-buffer-response')
const HttpError = require('./http-error')

function request (endpoint, route, options) {
const requestOptions = endpoint(route, options)

function request (requestOptions) {
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
requestOptions.body = JSON.stringify(requestOptions.body)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/with-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const request = require('./request')

function withDefaults (oldEndpoint, newDefaults) {
const endpoint = oldEndpoint.defaults(newDefaults)
const newApi = request.bind(null, endpoint)
const newApi = function (route, options) {
return request(endpoint(route, options))
}

newApi.endpoint = endpoint
newApi.defaults = withDefaults.bind(null, endpoint)
return newApi
Expand Down

0 comments on commit f57f14a

Please sign in to comment.