question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promises in fetch

See original GitHub issue

A month ago I started creating my own wiki/parser but as you know it’s a big pain in the ass. So I decided colaborate with another library, yesterday I found this one and I think is a great start. My idea is helping you with this, but I think we have different code-styles, and before start send you PRs I wanna tell you my thoughts:

  • Why we need more than one method? Now we have plaintext, from_api and parse. IMHO this library must be a unique stateless method:
import wikipediaWTF from `wikipedia-wtf`;

wikipedia(sentence {string}, options {language...})
  • Why we dont use Promises like?Better if we use something like:
wikipedia.from(sentence, options)
  .then(value => ...)
  .catch(error => ...)
  • If it’s a promise we can use the new standard async/await:
const knowledge = await wikipedia(sentence, options);
  • IMHO is better approach auto-parse the markup to a JavaScript Object
  • Now we have infobox and infobox_template, why we dont create a unique attribute?**
  • And the last one (for now), why we use grunt?? Maybe we have to move to babel + mocha via NPM tasks (zero-dependencies)

I think this library is a great start, but we have to create an consistent DSL for a better experience using it.

best,

javi

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
spencermountaincommented, Apr 25, 2018

hey all! this is implemented in 3.0.0

wtf.fetch(page) //returns a Promise

🎸

2reactions
niebertcommented, Apr 30, 2018

Spencer you are great, wonderful to have this library and other people seeing the value of your work. cheers, Bert

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make HTTP requests using Fetch API and Promises
The fetch function takes one mandatory argument, which is the path to the resource you want to fetch and returns a Promise that...
Read more >
How To Use JavaScript Promises and Fetch API - Andolasoft
Fetch () allows you to make network requests similar to XMLHttpRequest (XHR). The main difference is that the Fetch API uses Promises, ...
Read more >
fetch() - Web APIs | MDN
A fetch() promise only rejects when a network error is encountered (which is usually when there's a permissions issue or similar). A fetch() ......
Read more >
Promise API - The Modern JavaScript Tutorial
map(url => fetch(url)); // Promise.all waits until all jobs are resolved Promise.all(requests) .then( ...
Read more >
Using fetch() and a new Promise object to get API results
I've written an ES6 function using the new fetch() API and returning a new resolved promise with a data object or a rejected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found