1.1.2 • Published 2 years ago
As_Watson_SDK
Install
Create file .npmrc
in your project and add token into this file.
Because this is private package, you must add token.
@evan117:registry=https://gitlab.com/api/v4/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken=PEvzgszHyuG-ySDywWZ8
NPM install.
npm install @evan117/as_watson_sdk
npm install @as-watson-test/watson_sdk
Usage:React and React-Native
import React, {useState, useEffect} from 'react';
import API, {ProductListType} from '@as-watson-test/watson_sdk';
const App = () => {
const [data$, setData$] = useState<ProductListType>([]);
// Step1. Must use setBaseURL(<baseURL>) to initial.
API.setBaseURL(<baseURL>);
// Step2. Use getBaseURL() will return the set of baseURL.
console.log(API.getBaseURL())
// Step3. Use getProductList() method get Products data.
// Notice the Lifecycle.
useEffect(() => {
API.getProductList()?.then((data: ProductListType) => {
console.log(data);
setData$(data);
});
}, []);
return (
<>
</>
);
};
Properties
Prop | Type | Description |
---|
setBaseURL | function(url:string) | Use API.setBaseURL(<yourURL>) to setting baseURL. |
getBaseURL | return string | Use API.getBaseURL() will be return baseURL. |
getProductList | Promise<ProductListType> | Use API.getProductList() to get ProductListData. |
API Type
Type Name | Type |
---|
ProductType | code: string; name: string; promotionFirstTag: string; imagesUrl: string; oldPrice: string; markDownPrice: string; averageRating: number; productNumberOfReview: number; stockLevelStatus: string; |
ProductListType | Array<ProductType> |
ProductApiType | setBaseURL:(url: string) => void; getBaseURL:getBaseURL: () => string; getProductList:() => Promise<ProductListType> or void; |
Result
Angular |
---|
|
React |
---|
|