mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-20 03:14:06 -06:00
📇👋 -> Initialising API calls for #3
This commit is contained in:
parent
8b5cc69eda
commit
d1dc42dd3b
37
fetchjson/.gitignore
vendored
Normal file
37
fetchjson/.gitignore
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
dappyaccount.json
|
||||||
|
dappykeys.json
|
||||||
|
userkeys.json
|
||||||
|
useraccount.json
|
||||||
|
node_modules
|
||||||
|
.env
|
||||||
|
coverage
|
||||||
|
coverage.json
|
||||||
|
typechain
|
||||||
|
|
||||||
|
#Hardhat files
|
||||||
|
cache
|
||||||
|
artifacts
|
||||||
16
fetchjson/index.js
Normal file
16
fetchjson/index.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
exports.__esModule = true;
|
||||||
|
var axios_1 = require("axios");
|
||||||
|
var url = 'https://jsonplaceholder.typicode.com/todos/1';
|
||||||
|
axios_1["default"].get(url).then(function (response) {
|
||||||
|
// Called when we get a response from the API
|
||||||
|
// response.data properties: `id`, `title`, `completed`
|
||||||
|
var todo = response.data;
|
||||||
|
var id = todo.id;
|
||||||
|
var title = todo.title;
|
||||||
|
var completed = todo.completed;
|
||||||
|
logTodo(id, title, completed);
|
||||||
|
});
|
||||||
|
var logTodo = function (id, title, completed) {
|
||||||
|
console.log("\n The Todo with ID: ".concat(id, "\n Has a title of: ").concat(title, "\n Is it finished? ").concat(completed, "\n "));
|
||||||
|
};
|
||||||
28
fetchjson/index.ts
Normal file
28
fetchjson/index.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
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}
|
||||||
|
`);
|
||||||
|
}
|
||||||
58
fetchjson/package-lock.json
generated
Normal file
58
fetchjson/package-lock.json
generated
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
{
|
||||||
|
"name": "fetchjson",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 2,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "fetchjson",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.25.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "0.25.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
|
||||||
|
"integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.14.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.14.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
|
||||||
|
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"axios": {
|
||||||
|
"version": "0.25.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz",
|
||||||
|
"integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==",
|
||||||
|
"requires": {
|
||||||
|
"follow-redirects": "^1.14.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"follow-redirects": {
|
||||||
|
"version": "1.14.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
|
||||||
|
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
fetchjson/package.json
Normal file
15
fetchjson/package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "fetchjson",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^0.25.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user