Skip to content

Commit

Permalink
📇👋 -> Initialising API calls for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Feb 13, 2022
1 parent 8b5cc69 commit d1dc42d
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
37 changes: 37 additions & 0 deletions fetchjson/.gitignore
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions fetchjson/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions fetchjson/index.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 58 additions & 0 deletions fetchjson/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions fetchjson/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit d1dc42d

Please sign in to comment.