1.0.0 • Published 3 years ago

fetch-dummy v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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 including userId as the function parameter.

  • .promiseProto to fetch data asynchronously using javascript's promise feature by including userId as the function parameter.

  • .asyncAwaitProto to fetch data asynchronously using javascript's async/await features by including userId 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)

  1. dummy.callbackProto(2);

    returns String "Fetched Data: Donald Trump"

  2. dummy.callbackProto(-2);

    returns String "Error: Invalid ID"

  3. dummy.callbackProto();

    returns String "Error: ID missing"

.promiseProto(userId)

  1. dummy.promiseProto(1);

    returns String "Fetched Data: Joe Biden"

  2. dummy.promiseProto(-2);

    returns String "Error: Invalid ID"

  3. dummy.promiseProto();

    returns String "Error: ID missing"

.asyncAwaitProto(userId)

  1. dummy.asyncAwaitProto(4);

    returns String "Fetched Data: Howie Hawkins"

  2. dummy.asyncAwaitProto(-2);

    returns String "Error: Invalid ID"

  3. dummy.asyncAwaitProto();

    returns String "Error: ID missing"


License

ISC