使用fetch与REST API交互及Auth0认证集成
1. 使用fetch与未认证的REST API端点交互
在与未认证的REST API端点交互时,我们对现有的函数进行了优化。
1.1 获取单个问题
在 QuestionsData.ts 中,我们对 getQuestion 函数进行重构,以使用 http 函数从REST API获取单个问题,具体步骤如下:
1. 清除当前实现:
export const getQuestion = async (
questionId: number,
): Promise<QuestionData | null> => {
};
- 发起HTTP请求获取问题:
export const getQuestion = async (
questionId: number,
): Promise<QuestionData | null> => {
const result = await http<
QuestionDataFromServer
>({
path: `/questions/${questionId}`,
});
};
超级会员免费看
订阅专栏 解锁全文
28

被折叠的 条评论
为什么被折叠?



