UNPKG

fetch-xl

Version:

Fluent, interceptable (using es6 generators), configurable and loggable fetch wrapper

21 lines (16 loc) 601 B
import {InterceptorBuilder} from '../InterceptorBuilder'; import {TO_JSON_BODY} from '../interceptorPriorities'; import {propagateRequest} from '../propagateActions'; import is from '../../../util/is'; const jsonRequestInterceptor = InterceptorBuilder.interceptor('bodyToJson') .priority(TO_JSON_BODY) .interceptRequest(bodyToJson) .build(); export default jsonRequestInterceptor; function* bodyToJson(requestBuilder) { const body = requestBuilder.body; if (is.set(body)) { requestBuilder.body(JSON.stringify(body)); } yield propagateRequest(requestBuilder); }