title: Gatsby description: Gatsby guide for our application.

Overview

Welcome to the Gatsby guide. Here, you'll find all the information you need to get started with integrating our APIs into your Gatsby application.

Prerequisites

Before proceeding, ensure you have the following:

  • Node.js installed
  • Basic knowledge of command-line interface (CLI)
  • A code editor (e.g., VSCode)
  • An API key provided by our service

Setup Instructions

Since we provide API endpoints and keys for you to integrate into your Gatsby project, the setup process is straightforward.

  1. Obtain Your API Key: Ensure you have your API key ready. This key will be used to authenticate your requests to our APIs.

  2. Install Necessary Dependencies: If you haven’t already, ensure that your Gatsby project is set up with the necessary dependencies to make HTTP requests. Typically, you can use axios or the Fetch API for this purpose.

    To install axios, run the following command:

    npm install axios
    
  3. Configure Environment Variables: Create a .env file in the root of your Gatsby project to store your API key securely. Add the following line to your .env file:

    GATSBY_API_KEY=your-api-key-here
    

    Ensure that you have dotenv set up in your Gatsby project to use these environment variables.

  4. Using the API in Gatsby: Now you can use the API key and endpoints within your Gatsby components or pages. Here’s an example of how you might fetch data from an API endpoint:

    import React, { useEffect, useState } from 'react';
    import axios from 'axios';
    
    const MyComponent = () => {
      const [data, setData] = useState(null);
    
      useEffect(() => {
        axios.get('https://api.yourservice.com/endpoint', {
          headers: {
            'Authorization': `Bearer ${process.env.GATSBY_API_KEY}`
          }
        })
        .then(response => {
          setData(response.data);
        })
        .catch(error => {
          console.error('Error fetching data:', error);
        });
      }, []);
    
      return (
        <div>
          {data ? <pre>{JSON.stringify(data, null, 2)}</pre> : 'Loading...'}
        </div>
      );
    }
    
    export default MyComponent;
    
  5. Run the Gatsby Development Server: Start your Gatsby development server to see the integration in action:

    gatsby develop
    

    You can access your project at http://localhost:8000 to see the data fetched from the API.

Additional Information

For more details on how to use our APIs, please refer to our official documentation.


### Key Adjustments:
- **No Repository Cloning**: Removed any references to cloning a repository since the focus is purely on API integration.
- **Environment Setup**: Added steps for configuring environment variables (`.env` file) to securely handle the API key.
- **API Usage Example**: Provided a practical example of how to use the API within a Gatsby component, including fetching data with `axios` and using environment variables.
- **Running the Project**: Included instructions to run the Gatsby development server to test the integration.

This guide now focuses on the integration of your API into a Gatsby project, reflecting the actual process users would follow in your context.