Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using promises to fetch #1

Open
BigBaIIs opened this issue Feb 25, 2025 · 5 comments
Open

using promises to fetch #1

BigBaIIs opened this issue Feb 25, 2025 · 5 comments
Labels

Comments

@BigBaIIs
Copy link
Member

i think using axios or promises might be best way to fetch, as when I run curl -X GET:

Image

but beautiful way of displaying the data @Montana, will push some updates for promises/axios

@Montana Montana added enhancement New feature or request feasible plausible labels Feb 25, 2025
@Montana
Copy link
Member

Montana commented Feb 25, 2025

Hey @BigBaIIs,

Possibly a good idea, give it a shot. Create a pull request, and I'll merge the PR and we'll test it! Always room for improvement. Theoretically speaking we could add:

const response = await axios.get('https://doge.gov/api/kpis/Federal_Government');
         setFedData(response.data);`

If we used axios. If we ended up using promises, it would look like this:

new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          "aggregated": {
            "age_20_24_count": 52292,

Probably a good starting point is to try with axios, so run:

npm install axios

In the root directory, then import it via:

import axios from 'axios';

This then would use axios to pull from DOGE's API, which is: https://doge.gov/api/kpis/Federal_Government. We could also mix and match and pull data from the USA Spending API, so we'd be doing some API hopping. We may have to connect on a call.

@BigBaIIs
Copy link
Member Author

i agree @Montana, axios seems like a good starting point, as promises offer a bit more dynamic and flexible approach to handling asynchronous operations. with axios, you get a clean, promise-based HTTP client that simplifies making requests and managing responses, which can be especially handy when dealing with APIs or fetching data in a modern JS in this case react env.

@Montana
Copy link
Member

Montana commented Feb 25, 2025

Axios based promises structure pairs nicely with hooks like useEffect for fetching data cleanly and efficiently. Plus, it handles stuff like request cancellation and interceptors, which can be a lifesaver when you’re juggling API calls in a dynamic situation.

React Query would give us things like automatic refetching, stale-while-revalidate caching, and built-in loading/error states, so we can focus more on building features and less on wrangling data. What do you think about pairing it with axios in the dashboard @BigBaIIs?

@ASoreThroat
Copy link

great work guys! this is an awesome tool

@PerpIexity
Copy link
Member

found that axios works better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants