user2826: I am building an MERN stack app cardano dex tool, I want to use Blockfrost.
I have installed the SDK in Node.js backend, but there are only very few examples on how to get any kind of data from it.
The Blockfrost documentation gives more info and I know how to use it with fetch, but only url based and don't know how to implement QUERY PARAMETERS into the url request. Here is an example.
function getAssets(){
        fetch(`https://cardano-mainnet.blockfrost.io/api/v0/assets`,{
            headers: {
                "project_id":'API KEY'
            },
        })
        .then(res=>res.json())
        .then(data=>{console.log(data)})
    }
    getAssets()

If there is someone that could explain me a bit how to start using Blockfrost the proper way with a Node.js backend and basically get any kind of information.
Or maybe there is a better solution to get all data from the Cardano network, I have an relay node running with GraphQL, but getting data from that is very difficult if you just starting to use it and I don't know if it will keep working after the Alonzo fork.
Please someone that can help me pointing the right direction would be awesome.

user28: Using the Blockfrost SDK is pretty straight forward, as in this example:
import { BlockFrostAPI } from '../src/index';

async function run() {
  const API = new BlockFrostAPI({
    projectId: 'YOUR API KEY HERE', // see: https://blockfrost.io
  });

  try {
    const latestBlock = await API.blocksLatest();
    const latestEpoch = await API.epochsLatest();
    const health = await API.health();
    const address = await API.addresses(
      'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz',
    );

    console.log('address', address);
    console.log('latestEpoch', latestEpoch);
    console.log('latestBlock', latestBlock);
    console.log('health', health);
  } catch (err) {
    console.log('error', err);
  }
}

run();

Basically you can use any of Blockfrost endpoints in the SDK as well, check out the list of available calls. I recommend you using an IDE such as codium as it will autofill these as you code.

2826: <p>I am building an MERN stack app cardano dex tool, I want to use Blockfrost.</p>
<p>I have installed the <a href="https://github.com/blockfrost/blockfrost-js" rel="nofollow noreferrer">SDK</a> in Node.js backend, but there are only very few examples on how to get any kind of data from it.</p>
<p>The <a href="https://docs.blockfrost.io/" rel="nofollow noreferrer">Blockfrost documentation</a> gives more info and I know how to use it with fetch, but only url based and don't know how to implement QUERY PARAMETERS into the url request. Here is an example.</p>
<pre><code>function getAssets(){
        fetch(`https://cardano-mainnet.blockfrost.io/api/v0/assets`,{
            headers: {
                &quot;project_id&quot;:'API KEY'
            },
        })
        .then(res=&gt;res.json())
        .then(data=&gt;{console.log(data)})
    }
    getAssets()
</code></pre>
<p>If there is someone that could explain me a bit how to start using Blockfrost the proper way with a Node.js backend and basically get any kind of information.</p>
<p>Or maybe there is a better solution to get all data from the Cardano network, I have an relay node running with GraphQL, but getting data from that is very difficult if you just starting to use it and I don't know if it will keep working after the Alonzo fork.</p>
<p>Please someone that can help me pointing the right direction would be awesome.</p>
 28: <p>Using the Blockfrost SDK is pretty straight forward, <a href="https://github.com/blockfrost/blockfrost-js/blob/master/examples/api.ts" rel="nofollow noreferrer">as in this example</a>:</p>
<pre><code>import { BlockFrostAPI } from '../src/index';

async function run() {
  const API = new BlockFrostAPI({
    projectId: 'YOUR API KEY HERE', // see: https://blockfrost.io
  });

  try {
    const latestBlock = await API.blocksLatest();
    const latestEpoch = await API.epochsLatest();
    const health = await API.health();
    const address = await API.addresses(
      'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz',
    );

    console.log('address', address);
    console.log('latestEpoch', latestEpoch);
    console.log('latestBlock', latestBlock);
    console.log('health', health);
  } catch (err) {
    console.log('error', err);
  }
}

run();
</code></pre>
<p>Basically you can use any of Blockfrost endpoints in the SDK as well, check out <a href="https://github.com/blockfrost/blockfrost-js/wiki/BlockFrostAPI.md" rel="nofollow noreferrer">the list of available calls</a>. I recommend you using an IDE such as <a href="https://vscodium.com/" rel="nofollow noreferrer">codium</a> as it will autofill these as you code.</p>
