Make Interface for What Api You Can Get
interface ITodo {
userId: number;
id: number;
title: string;
completed: boolean;
}
Make Call With Async and Await Arrow Function
const getTodo = async (): Promise<ITodo> => {
const response = await fetch("https://jsonplaceholder.typicode.com/todos/1");
return await response.json();
};
and Last Get The Data in Another Async Await Arrow Function
const getTodoData = async (): Promise<void> => {
const result = await getTodo();
console.log(result);
};
getTodoData();
Top comments (0)