@httpc/client
Version:
httpc client for building function-based API with minimal code and end-to-end type safety
25 lines • 897 B
JavaScript
export 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);
};
}
export function AuthHeader(schema, value) {
return Header("Authorization", () => {
const val = typeof value === "function" ? value() : value;
return val !== undefined && val !== null && val !== "" ? `${schema} ${val}` : undefined;
});
}
export 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);
};
}
//# sourceMappingURL=middlewares.js.map