diff --git a/fetchjson/.gitignore b/fetchjson/.gitignore new file mode 100644 index 0000000000000..ef15aa73b1698 --- /dev/null +++ b/fetchjson/.gitignore @@ -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 \ No newline at end of file diff --git a/fetchjson/index.js b/fetchjson/index.js new file mode 100644 index 0000000000000..3126c4821748d --- /dev/null +++ b/fetchjson/index.js @@ -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 ")); +}; diff --git a/fetchjson/index.ts b/fetchjson/index.ts new file mode 100644 index 0000000000000..ce01ec65be876 --- /dev/null +++ b/fetchjson/index.ts @@ -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} + `); +} \ No newline at end of file diff --git a/fetchjson/package-lock.json b/fetchjson/package-lock.json new file mode 100644 index 0000000000000..d00e5a8be4fa3 --- /dev/null +++ b/fetchjson/package-lock.json @@ -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==" + } + } +} diff --git a/fetchjson/package.json b/fetchjson/package.json new file mode 100644 index 0000000000000..d6b72c98b8619 --- /dev/null +++ b/fetchjson/package.json @@ -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" + } +}