The runtime lib of the Nad project.
yarn add @huolala-tech/nad-runtime
or
npm install @huolala-tech/nad-runtime --save
import { NadInvoker } from '@huolala-tech/nad-runtime';
// This code will request http://localhost/users/123 with GET mtehod.
const getUserInfo = async () => {
return await new NadInvoker('http://localhost').open('GET', '/users/{id}').addPathVariable('id', 123).execute();
};
import { NadInvoker } from '@huolala-tech/nad-runtime';
// This code will request http://localhost/getUser?id=123 with GET mtehod.
const getUserInfo = async () => {
return await new NadInvoker('http://localhost').open('GET', '/getUser').addRequestParam('id', id).execute();
};
import { NadInvoker } from '@huolala-tech/nad-runtime';
// This code will request http://localhost/getUser?id=1&type=2 with GET mtehod.
const getUserInfo = async () => {
return await new NadInvoker('http://localhost')
.open('GET', '/getUser')
.addModelAttribute({ id: 1, type: 2 })
.execute();
};
import { NadInvoker } from '@huolala-tech/nad-runtime';
// This code will request http://localhost/userService with POST mtehod and send payload {"id":123}.
const getUserInfo = async () => {
return await new NadInvoker('http://localhost').open('POST', '/userService').addRequestBody({ id: 123 }).execute();
};