GithubHelp home page GithubHelp logo

jesperjohansson / gatsby-source-exchange-rates-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 155 KB

Gatsby source plugin for Exchange Rates API

License: MIT License

JavaScript 100.00%
gatsby gatsby-plugin gatsby-source exchangeratesapi

gatsby-source-exchange-rates-api's Introduction

NPM version

Description

A Gatsby source plugin for retrieving data from the exchangeratesapi.io API.

How to install

Install the package as a dependency

yarn add gatsby-source-exchange-rates-api

Add the plugin to your gatsby-config.js file

// gatsby-config.js
{
  plugins: [
    {
      resolve: 'gatsby-source-exchange-rates-api',
    }
  ]
}

How to query data

You can select the endpoint to fetch from by specifying endpoint in the plugins options object. The default is the endpoint latest. You can also specify query parameters as a query object (default is no query).

Exchange Rates API documentation: (Github) (Website)

// gatsby-config.js
{
  resolve: 'gatsby-source-exchange-rates-api',
  options: {
    endpoint: 'history', // (optional) default is "latest"
    query: { // (optional)
      base: 'SEK',
      symbols: 'EUR,USD',
      start_at: '2019-02-01',
      end_at: '2019-02-03',
    },
  }
}

If you use the default endpoint latest you will get one node with the latest rates. If you use the endpoint history there will be multiple rates returned as an array instead.

Latest endpoint usage example

// Get the latest rates
useStaticQuery(graphql`
  query {
    exchangeRates {
      id
      date
      USD
    }
  }
`)

History endpoint usage example

// Get an array of history rates
useStaticQuery(graphql`
  query {
    allExchangeRates {
      edges {
        node {
          id
          date
          USD
          EUR
        }
      }
    }
  }
`)

Credits

Madis Väin, creator of the Exchange Rates API

https://exchangeratesapi.io/

gatsby-source-exchange-rates-api's People

Contributors

dependabot[bot] avatar jesperjohansson avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.