I have react native app.i want get data from the asp.net core web API .I want to to access localhost asp.net core web API from outside(from react native app)
Asked
Active
Viewed 368 times
1 Answers
0
You can use many 3rd party library for HTTP request such as axios, fetch even XMLHttpRequest as you want to access core web API. You can use the following approaches it doesn't matter what's your endpoint.
fetch('https://jsonplaceholder.typicode.com/posts/1', {
method: 'GET'
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
this.setState({
data: responseJson
})
})
.catch((error) => {
console.error(error);
});
using XMLHttpRequest
var xhr = new XMLHttpRequest()
xhr.addEventListener('load', () => {
console.log(xhr.responseText)
})
xhr.open('GET', 'https://dog.ceo/api/breeds/list/all')
xhr.send()
using axios
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
});

ANIK ISLAM SHOJIB
- 3,002
- 1
- 27
- 36