Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is fetch() data from API and get() data from API the same?

I have an assignment to: use the method GET to fetch api info from http://api.example.com/. I'm also told to only use: Javascript/Reactjs

However, everywhere I search, I can only fetch the data. Are these two the same thing? Or am I looking at the wrong tutorials?

import React, { Component } from 'react';

class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      items: [],
      isLoaded: false,
    }
  }

  componentDidMount() {
    fetch('https://jsonplaceholder.typicode.com/users')
      .then(res => res.json())
      .then(json => {
        this.setState({
          isLoaded: true,
          items: json,
        })
      });
  }

  render() {

    var { isLoaded, items } = this.state;

    if (!isLoaded) {
      return <div>Loading...</div>
    }
    else {
      return (
        <div className="App">
          <ul>
            {items.map(item => (
              <li key={item.uid}>
                Name: {item.name} | Email:{item.email}
              </li>
            ))};
          </ul>
        </div>
      );
    }
    
  }

}

export default App;
like image 806
rickandmorty Avatar asked Mar 11 '26 18:03

rickandmorty


1 Answers

they are interchangeable, as a technical jargon from the field, "get data from api" and "fetch data from the api" means the same thing.

in javascript, nowadays, we use the Fetch API to interact with an api, using HTTP request methods like GET, HEAD, POST, DELETE.

unfortunately i don't know a page or repository listing these jargons

like image 193
oieduardorabelo Avatar answered Mar 13 '26 06:03

oieduardorabelo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!