0.0.5-alpha8 • Published 3 years ago
easier-requests v0.0.5-alpha8
Table of Contents
easier-requests
easier-requests
is a package to allow HTTP requests to be made in a more
synchronous manner inside an async function.
Install
npm i easier-requests
Usage
// Import requester instance from easier-requests module
import requester from "easier-requests";
// Requester.get() is designed to be used in an async function
async function makeCards() {
const cardsContainer = document.querySelector('.cards-container');
const id = requester.createUniqueID(); // get a unique id
// perform request
await requester.get('https://example.herokuapp.com/articles', id);
// retrieve response, checking for an error
const response = requester.response(id);
if (response === undefined) {
const errorMessage = 'ERROR RETRIEVING ARTICLES: ' +
`${requester.error(id)}`;
const errorDisplay = document.createElement('h1');
errorDisplay.textContent = errorMessage;
cardsContainer.appendChild(errorDisplay);
return;
}
// process data
const topics = response.data.articles;
for (let topic in topics)
for (let article of topics[topic]) {
const card = makeCard(article);
cardsContainer.appendChild(card);
};
}
0.0.5-alpha8
3 years ago
0.0.5-alpha7
4 years ago
0.0.5-alpha6
4 years ago
0.0.5-alpha5
4 years ago
0.0.5-alpha4
4 years ago
0.0.5-alpha2
4 years ago
0.0.5-alpha3
4 years ago
0.0.5-alpha1
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.3-rc1
4 years ago
0.0.3-alpha3
4 years ago
0.0.3-alpha2
4 years ago
0.0.3-alpha1
4 years ago
0.0.1
4 years ago
0.0.2
4 years ago
0.0.1-rc1
4 years ago
0.0.0
4 years ago