How to make API Call in react with wikipedia API project and Youtube API project part -2 UCS - Unleash-Coding-Skills

Saturday, 16 June 2018

How to make API Call in react with wikipedia API project and Youtube API project part -2 UCS

I will explain with code how to make API call in react by making an API call to the Wikipedia API.
For part-1 go to this link:

click here: API call making in React part-1

click on above link for part-1

The thing you must remember is you must have state variable to save response whenever the state is changed like when you searched for a term you can have change in state.

fetch(`https://crossorigin.me/https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${this.state.query}`)
.then(response => response.json())
.then(data => this.setState({ result: data }));


Note that you have a cross-origin extension in your chrome and make it on to get the API response.

The fetch().then(response() => response.json(..)).then(..);

is the main thing to make API request using React. The wiki-search project will appear like this at the end it is very basic web app using the react with only 3 files to make one for search bar component, indes.js, and one display area component.This is best way to start with react.

The project image is


The link to the project so you can study for better usage

click here: Wiki-Search-Link

Use the above link for the project details

No comments:

Post a comment