This is confusing me alot. I'm using Axios POST and GET requests but GET request gives me an error:
GET http://127.0.0.1:3000/financierft/profile 404 (Not Found)
While POST request works perfectly. Here's the code to GET data:
async function getStakedNFT() {
try{
await axios.get('http://127.0.0.1:3000/financierft/profile')
.then(response => console.log(response))
} catch(e){
console.log(e)
}
}
Here's the code to send a test request:
POST http://127.0.0.1:3000/financierft/profile
Content-Type: application/json
{
"Address":"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
"Id":"000",
"NFTClass":"A",
"walletAddress":"0x241267378C00b493c5f8D26eebD81beC8Ad556f9"
}
Here's the route.js file:
const express = require('express')
const router = express.Router()
const nftDataTemplate = require('../NFTs/NFTData')
router.post('/profile', async (request, response)=>{
const newNftData = new nftDataTemplate({
Address: request.body.Address,
Id: request.body.Id,
NFTClass: request.body.NFTClass,
walletAddress: request.body.walletAddress
})
newNftData.save()
.then(data=>{
response.json(data)
})
.catch(error=>{
response.json(error)
})
})
module.exports = router
And also I'm using POST request from front-end UI which also works perfectly fine:
function StakeNft(){
try{
const NFTData = {
walletAddress,
Address,
Id,
NFTClass,
}
axios.post('http://127.0.0.1:3000/financierft/profile', NFTData)
.then(response=>console.log(response.data))
this.setState({
walletAddress:'',
Address:'',
Id:'',
NFTClass:''
})
}
catch(e){
console.log(e)
}
}
I've tried using localhost in place of 127.0.0.1 but I'm still getting the same error. Does anyone has any clue as to am I doing wrong?.