fetch-dummy v1.0.0
fetch-dummy-data
Fetching dummy data asynchronously
A dummy data fetching module using javascript callback
, promise
and async/await
.
fetc-dummy-data allows you to check and understand the working of javascipt's asynchronous function calls by using three different ways, namely: 1. JavaScript Callbacks 2. JavaScript Promises 3. JavaScript Async
Features
.callbackProto
to fetch data asynchronously using javascript's callback feature by includinguserId
as the function parameter..promiseProto
to fetch data asynchronously using javascript's promise feature by includinguserId
as the function parameter..asyncAwaitProto
to fetch data asynchronously using javascript's async/await features by includinguserId
as the function parameter.
Demo
Installation
Importing
Fetching Dummy Data
API
Usage
Demo
Running callback
.callbackProto
Running promise
.promiseProto
Running async/await
.asyncAwaitProto
Installation
npm i --save-dev install fetch-dummy-data@1.0.4
yarn add -D install fetch-dummy-data@1.0.4
Importing
fetch-dummy-data is a default export so it can be imported with whatever name you like.
const dummy = require('fetch-dummy-data@1.0.4');
Fetching Dummy Data
API
callbackProto(userId)
.callbackProto
:
- parameters:
Number
the userId of the data to be fetched.
promiseProto(userId)
.promiseProto
:
- parameters:
Number
the userId of the data to be fetched.
asyncAwaitProto(userId)
.asyncAwaitProto
:
- parameters:
Number
the userId of the data to be fetched.
Usage
.callbackProto(userId)
dummy.callbackProto(2);
returns
String
"Fetched Data: Donald Trump"dummy.callbackProto(-2);
returns
String
"Error: Invalid ID"dummy.callbackProto();
returns
String
"Error: ID missing"
.promiseProto(userId)
dummy.promiseProto(1);
returns
String
"Fetched Data: Joe Biden"dummy.promiseProto(-2);
returns
String
"Error: Invalid ID"dummy.promiseProto();
returns
String
"Error: ID missing"
.asyncAwaitProto(userId)
dummy.asyncAwaitProto(4);
returns
String
"Fetched Data: Howie Hawkins"dummy.asyncAwaitProto(-2);
returns
String
"Error: Invalid ID"dummy.asyncAwaitProto();
returns
String
"Error: ID missing"
License
ISC
3 years ago