I am trying to make simple API Fetch with axios through a simple form,input, and everything works fine untill I pass user into my axio get.'
first error: GET https://api.github.com/users/$%7Buser%7D 404 second error: createError.js:16 Uncaught (in promise) Error: Request failed with status code 404 '''
function App() {
let getUser = (e) =>{
e.preventDefault()
const user = e.target.elements.username.value
axios.get("https://api.github.com/users/${user}")
.then((res) => {
console.log(res)
})
}
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">HTTP&API</h1>
</header>
<UserForm getUser={getUser}/>
</div>
);
}
'''
I am new to a web dev, any help would be appreciated.
either concatenate the string
axios.get("https://api.github.com/users/" + user)
or use template strings
axios.get(`https://api.github.com/users/${user}`)