UNPKG

axios-feign

Version:

open feign of typescript use axios

48 lines 1.52 kB
import format from 'string-format'; async function httpInvoke(ths, method, url, param, body) { const axois = ths._axios; for (const key in param) { const value = param[key]; param[key] = encodeURI(value); } const fmtUrl = format(url, param); const rt = await axois[method](fmtUrl, body); return rt.data; } export function get(url) { return function (target, propertyKey, descriptor) { descriptor.value = async function (param, body) { const rt = await httpInvoke(this, "get", url, param, body); return rt; }; return descriptor; }; } export function post(url) { return function (target, propertyKey, descriptor) { descriptor.value = async function (param, body) { const rt = await httpInvoke(this, "post", url, param, body); return rt; }; return descriptor; }; } export function put(url) { return function (target, propertyKey, descriptor) { descriptor.value = async function (param, body) { const rt = await httpInvoke(this, "put", url, param, body); return rt; }; return descriptor; }; } export function del(url) { return function (target, propertyKey, descriptor) { descriptor.value = async function (param, body) { const rt = await httpInvoke(this, "delete", url, param, body); return rt; }; return descriptor; }; } //# sourceMappingURL=FeignDecorator.js.map