mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-20 03:14:06 -06:00
28 lines
736 B
TypeScript
28 lines
736 B
TypeScript
import axios from 'axios';
|
|
|
|
const url = 'https://jsonplaceholder.typicode.com/todos/1';
|
|
|
|
interface Todo {
|
|
id: number; // Id of the note (not userId, as userId is ignored)
|
|
title: string;
|
|
completed: boolean;
|
|
}
|
|
|
|
axios.get(url).then(response => {
|
|
// Called when we get a response from the API
|
|
// response.data properties: `id`, `title`, `completed`
|
|
const todo = response.data as Todo;
|
|
const id = todo.id;
|
|
const title = todo.title;
|
|
const completed = todo.completed;
|
|
|
|
logTodo(id, title, completed);
|
|
});
|
|
|
|
const logTodo = (id: number, title: string, completed: boolean) => {
|
|
console.log(`
|
|
The Todo with ID: ${id}
|
|
Has a title of: ${title}
|
|
Is it finished? ${completed}
|
|
`);
|
|
} |