@pendant/api
v0.0.6
Published
> TODO: description
Downloads
4
Readme
api
快速请求 CODING OPEN API
Usage
import { setConfig, fetchApi } from '@pendant/api';
setConfig({ clientId: '1234565' });
const ProjectListDemo = () => {
const [describeCodingProjects, setDescribeCodingProjects] = useState({});
const { response, error } = describeCodingProjects;
useEffect(() => {
fetchApi('DescribeCodingProjects', query).then((res) => setDescribeCodingProjects(res));
}, [])
if (error || response?.Error) {
return <>获取数据错误</>
}
if (response?.Data?.ProjectList instanceof Array) {
return response?.Data?.ProjectList.map(project => <div>{project.Name}<div>)
}
return <>loading</>;
}
export default ProjectListDemo;
Api
setConfig
设置 api
的配置
{
clientId: string;
fetch?: Parameters<typeof fetch>;
}
| 参数 | 说明 | 类型 | 默认值 | | -------- | -------------------------------------------------------------------------------------------------------------- | ------------------------ | ------ | | clientId | 客户端 ID | string | - | | fetch | fetch 的默认参数[RequestInfo | URL, { headers: RequestInit['headers'] }],在发送请求的时候会合并到 参数里面。 | Parameters | - |
fetchApi
fetchApi('DescribeCodingProjects', query).then((res) => console.log(res));
| 参数 | 说明 | 类型 | 默认值 | | ------ | ----------------- | ------ | ------ | | action | 需要调用的业务 id | string | - | | query | 请求参数 | Object | - |
getContext
获取应用的上下文信息
const { accessToken, apiUrl } = await getContext();