@httpc/client
Version:
httpc client for building function-based API with minimal code and end-to-end type safety
31 lines • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryParam = exports.AuthHeader = exports.Header = void 0;
function Header(header, value) {
return (request, next) => {
const val = typeof value === "function" ? value() : value;
if (val !== undefined && val !== null) {
request.headers.set(header, val);
}
return next(request);
};
}
exports.Header = Header;
function AuthHeader(schema, value) {
return Header("Authorization", () => {
const val = typeof value === "function" ? value() : value;
return val !== undefined && val !== null && val !== "" ? `${schema} ${val}` : undefined;
});
}
exports.AuthHeader = AuthHeader;
function QueryParam(key, value) {
return (request, next) => {
const val = typeof value === "function" ? value() : value;
if (val !== undefined && val !== null) {
request.query.set(key, val.toString());
}
return next(request);
};
}
exports.QueryParam = QueryParam;
//# sourceMappingURL=middlewares.js.map