theastrologer-api icon indicating copy to clipboard operation
theastrologer-api copied to clipboard

Issues calling the API

Open justinzarate opened this issue 2 years ago • 1 comments

After building everything there seems to be an issue of the API being called. I tried to rewrite it a few times and when I run and compile the code everything works great, but will not pull up the data for the daily horoscopes.

When checking the network part of the developer tools it looks like there isn't any request being made.

This is currently what I have in my api.js file.

export const getSigns = () => {
return fetch(
      "http://sandipbgt.com/theastrologer/api/sunsigns/"
      ).then((response) => response.json());
};

export const getHoroscope = (sign, timeframe) => {
  return fetch(
    'https://sandipbgt.com/theastrologer/api/horoscope/${sign}/${timeframe}/'
  )
  .then((response) => response.json())
  .then(({horoscope}) => horoscope);
};

The updated file is on my github. Can it be something to do with how it's being called on my Horoscope.JSX file?

here is how my Horoscope.JSX file looks

import { useEffect, useState } from "react";
import { getHoroscope } from '../services/api';

export const Horoscope = ({sign, timeframe}) => {
    const [horoscope, setHoroscope] = useState([]);

    useEffect(() => {
        getHoroscope(sign, timeframe).then(setHoroscope);
    }, [sign, timeframe]);

    return (
        <div>
            <h2>
                {timeframe}, your horoscope for {sign} is...
            </h2>
            <p>{horoscope}</p>
        </div>
    );    
};

Screen Shot 2022-11-03 at 12 19 03 PM

justinzarate avatar Nov 09 '22 06:11 justinzarate

The api is not upto date. So I request you to look for another new api.

sandipbgt avatar Nov 15 '22 16:11 sandipbgt