Skip to content

Add dummy backend data fetching#4

Open
haaspt wants to merge 10 commits intodevelopfrom
haaspt/api-calls-dev
Open

Add dummy backend data fetching#4
haaspt wants to merge 10 commits intodevelopfrom
haaspt/api-calls-dev

Conversation

@haaspt
Copy link
Member

@haaspt haaspt commented Oct 5, 2021

Overview

This PR replaces the placeholder weather forecast data in the frontend with actual data fetching from the backend.

To accomplish this I added a /forecast/ endpoint to the backend. Currently it just randomly generates a list of conditions and temperatures regardless of what location is queried.

The frontend static data has been replaced with an async fetch call in WeatherForecast.js. This also involved adding additional states to store the data and the loading status.

How to Test

  • Spin up the docker containers
  • Navigate to localhost:8000/docs and test out the new endpoint
  • Navigate to localhost:3000 and observe how weather data is dynamically populated
  • [Optional] Kill only the backend service and observe how the weather data never populates and the widgets are stuck in a "loading" state.

Screen Shot 2021-10-05 at 4 22 02 PM

Screen Shot 2021-10-05 at 4 22 24 PM

@haaspt haaspt requested a review from lzkelley October 5, 2021 23:30

origins = ["http://localhost", "http://localhost:3000"]

app.add_middleware(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frontend is technically located at a different origin so we have to enable CORS so the requests will be allowed. More here.

// TODO: Add isError state handling
}
)
}, [locationData]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useEffect accepts a final argument that describes its dependencies. Anytime a dependency is updated the effect will run again. In this case we just need this to run once when the container mounts so we shouldn't have any dependencies. However, since we're using locationData in our API call we need to include it as a dependency (even if we don't expect it to change inside the container)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant