2

I'm trying to fetch API using this but it's not working.

async componentDidMount(){
  const url = "https://jsonplaceholder.typicode.com/posts";          
  const response = await fetch(url);      
  const data = await response.json();      
  console.log(data);
}
Najam Us Saqib
  • 3,190
  • 1
  • 24
  • 43

1 Answers1

0

You could use axios to make an API call.

The sample code is as below

const authenticateUser = async  (username: string, password: string) : Promise<boolean> => {

    const loginData = {
        "Username": username,
        "Password": password
    }

    const api = axios.create({
        baseURL: "https://website.com/api/services"
    })

    const resp = await api.post("/ValidateUserPost", loginData)

    if(resp.data != null && resp.data.userId != null && resp.data.userId > 0){               
        return true
    } 
    else
        return false
};
Ashish Tripathi
  • 580
  • 4
  • 18