whalecloud-dxp-api-react-native
v1.0.2
Published
This section explains how to use the SDK and illustrates it with an example: - This chapter is essential to learn - For specific business development, see [Bussiness Scenario](https://www.digchan.info/en-US/dxp/user-sso/sign-up) - The Business Scenario pr
Downloads
67
Maintainers
Readme
DXP API SDK
This section explains how to use the SDK and illustrates it with an example:
- This chapter is essential to learn
- For specific business development, see Bussiness Scenario
- The Business Scenario provides detailed business interface call processes, which can guide your development based on the flowcharts.
- For interface details, see Experience Api
- The interface details include specific input parameters, output parameters, and exception information
- To call an interface in the SDK: const response = DXPRequest.BusinessCategory.SpecificInterface(inputParameters)
- During development, some common interfaces are available: Common Api
Integration
Add the npm package reference to the
package.json
in your project, for example:"dependencies": { "whalecloud-dxp-api-react-native": "1.0.0" }
Run
yarn add whalecloud-dxp-api-react-native --registry=https://verdaccio.digchan.info/
in the root directory of your project to install the new dependency.Rebuild and run your React Native project.
Configuration
Modify the network request configuration object Set the request URL(basePath),Initialize using the DXPRequest.initConfig method
import { DXPRequest } from "./DXPHttpRequest";
// Create configuration object
const configuration = new Configuration({
basePath: 'https://demo.com/path', // Replace with your API base URL
});
// Initialize configuration information
DXPRequest.initConfig(configuration);
Set Auth Token
DXP provides various user authentication methods. This section explains how to configure user login authentication using a username and password. For more details, please refer to this link
import { DXPRequest } from "./DXPHttpRequest";
const request={
loginAcct: "account number",
password: "password"
}
DXPRequest.pwdLogin(request)
.then(response=>{
// response contains information returned after login
// response.resultMsg is a message returned by the backend upon successful login
console.log(response.resultMsg);
// A token is returned upon successful user login
console.log(response.data.token);
// User information, such as mobile
console.log(response.data.userInfo.mobile);
// Set the obtained token information to a global variable (this step might be omitted later)
DXPRequest.setToken({accessToken:"token"});
})
.catch(error=>{
// Exception information obtained when login fails
console.log(error.resultMsg);
});
Usage Example
After a successful user login, call Query Account Detail to get account details.
import { DXPRequest } from "./DXPHttpRequest";
const acctNbr='12345678';
DXPRequest.AccountManagement.queryAccountDetail(acctNbr)
.then(response=>{
// response contains the query result object
// response.resultMsg is a message returned upon successful query
console.log(response.resultMsg);
// Account name retrieved from the query
console.log(response.data.acctName);
})
.catch(error=>{
// Exception information obtained when the call fails
console.log(error.resultMsg);
});
Advanced Features
How to Set Interceptors
Interceptors can be used to perform various operations:
- Request Interceptor
- You can add request headers uniformly through a request interceptor
import { DXPRequest } from "./DXPHttpRequest";
DXPRequest.interceptors.request.use(
config => {
// Add dynamic properties to request headers before sending the request
config.headers = {
...config.headers,
language:"English"
,
};
return config;
},
error => {
// Do something with request error
return Promise.reject(error);
}
);
- Response Interceptor
import { DXPRequest } from "./DXPHttpRequest";
// Add response interceptors
DXPRequest.interceptors.response.use(
response => {
// Do something with response data
return response;
},
error => {
// Do something with response error
console.log(error);
return error;
}
);