@loong-js/service
v0.5.0
Published
This is loong service
Downloads
5
Readme
@loong-js/service
This is loong service.
📦 Installation
npm install @loong-js/service
🔨 Usage
import { request, configure } from "@loong-js/service";
configure({
middlewares: [
async (ctx, next) => {
console.log("anonymous before", ctx);
await next();
console.log("anonymous after", ctx);
},
],
requests: {
"/api": {
middlewares: [
async (ctx, next) => {
console.log("requests anonymous before", ctx);
try {
await next();
} catch (error) {
console.log([error]);
}
if (ctx.response.status !== 200) {
throw new Error("错误");
}
console.log("requests anonymous after", ctx);
},
],
},
},
});
async function getUser() {
const result = await request("/api/user1", {
// baseUrl: "https://www.xxx1.com",
data: 1,
timeout: 3000,
ingoreError: true,
});
console.log(result);
}
getUser();
🐛 Issues
If you find a bug, please file an issue on our issue tracker on GitHub.
🏁 Changelog
Changes are tracked in the CHANGELOG.md.
📄 License
@loong/service
is available under the MIT License.