Nearby lessons

39 of 44

🌐 ReactJS – Fetch API

📌 What is API?

How to Fetch Data from an API?

API stands for Application Programming Interface. It acts as a software intermediary that allows two applications to communicate. APIs provide an accessible way to extract and share data within and across organizations.

According to Wikipedia: In computer programming, an API is a set of subroutine definitions, protocols, and tools for building software and applications.

📌 What is an API?

  • API stands for Application Programming Interface
  • It allows two applications to talk to each other
  • Helps to extract and share data across organizations
  • It is a set of subroutine definitions, protocols, and tools for building software

⚙️ What is fetch() Function?

  • The fetch() method is used to request data from a server
  • It can call any API that returns JSON or XML
  • It requires a single parameter – the API URL
  • It returns a Promise that resolves with the response data

🧑‍💻 Example: Fetch Data in React

Below is an example of using fetch() inside a React component.

It fetches posts from https://jsonplaceholder.typicode.com/posts and displays their titles.

React Playground
export default function App() {
  return (
    <div>
      <h1>Hello React!</h1>
    </div>
  );
}

🧠 Test Your Knowledge

4 Questions

Progress: 0 / 4
Keep Going!React - Redux Introduction