reactjs axios cant get api data

axios react
how to display data from api in react js
reactjs fetch api example
reactjs api call example
react axios get json data
axios react hooks
axios tutorial
react axios vs fetch

I can't get my api data from https://randomuser.me/api/

But when I'm using another api like http://dummy.restapiexample.com/api/v1/employees it works.

The error:

import React from "react";
import "./App.css";
import Start from "./start";

function App() {
  return (
    <div className="App">
      <Start />
    </div>
  );
}

export default App;

start.js

import React, { Component } from "react";
import Axios from "axios";

class Start extends Component {
  constructor(props) {
    super(props);

    this.state = {
      results: []
    };
  }

  componentDidMount() {
    Axios.get("https://randomuser.me/api/").then(res => {
      const results = res.data;
      this.setState({ results });
      console.log(results);
    });
  }

  render() {
    return (
      <div>
        {this.state.results.map(result => {
          return <div>{result.id}</div>;
        })}
      </div>
    );
  }
}
export default Start;

Problem is that http://dummy.restapiexample.com/api/v1/employees returns array while https://randomuser.me/api/ returns object. Try changing to

componentDidMount() {
    Axios.get("https://randomuser.me/api/").then(res => {
      const results = res.data.results;
      this.setState({ results });
      console.log(results);
    });
  }

Consuming REST APIs In React With Fetch And Axios, APIs are what we can use to supercharge our React applications with data. There are certain operations that can't be done on the client-side,  I am trying to use a Node.JS application to make and receive API requests. It does a get request to another server using Axios with data it receives from an API call it receives.

You have to use res.data.results. It comes in results object.

How to Display API Data Using Axios with React, How to Display API Data with Axios in React (Axios React Tutorial) the component doesn't care and we only have to change the API call. React API Call to Get Pokemon JSON Data using Axios and useEffect in ReactJS in Hindi #55

Please check your JSON data last line you missed the "}]" typo error in http://dummy.restapiexample.com/api/v1/employees

componentDidMount() {
    Axios.get("http://dummy.restapiexample.com/api/v1/employees").then(res => {
      const results = res.data;
      this.setState({ results: results });
    });
  }

Using data in React with the Fetch API and axios, The first time the application renders, the data won't have been received — it can take seconds. We want to trigger the method to fetch the users  The idea is still the same: check to see if loading is in process and either render the data we get back or let the user know things are still loading. To make the request to the API, we’ll need to create a function. We’ll call the function getUsers(). Inside it, we’ll make the request to the API using axios.

Using Axios with React to Make API Requests, The most common type of HTTP request is the GET request. It allows us to retrieve data from an API and use that data in a React app. There is  Axios is a library used to make HTTP requests from the browser. Read on to learn how to use Axios with React to make API requests and display the response. What is Axios? Axios is an hugely popular (over 52k stars on Github) HTTP client that allows us to make GET and POST requests from the browser.

Axios or fetch(): Which should you use?, Axios automatically converts the data to JSON, so you don't have to. // axios The Fetch API doesn't have an onprogress handler. Instead, it  These requests are made through API (Application Programming Interface). The API helps in communicating with the server via a URL in the form of GET, POST, UPDATE, and Delete. Now, here Axios comes into the light. Axios is a library used to make HTTP requests from the browser via Node and Express.js platform.

Simplest way to use axios to fetch data from an api in ReactJS, I won't explain what is an API, What is Axios because you can google it Hola we have successfully called our data from an API to our react  This tutorial will teach you how to use Axios to fetch data and then how to manipulate it and eventually display it on your page with filtering functionality. You will learn how to use the map,

Comments
  • const results = res.data; replace const results = res.results;
  • What is the result of your console.log(results)?
  • @SteFandy Be sure to always check structure of response so you can setup your code accordingly. You can accept the answer if solution resolved your issue.