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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With