Json-server & Axios

Example of an express app

app.get(‘/’, async (request, response) => {
    axios.post(‘http://localhost:3001/posts’, {
        id: 3,
        title: ‘test2’
    }).then(resp => {
        console.log(resp.data);
    }).catch(error => {
        console.log(error);
    });
    // response.send(‘hello’);
    const getDb = await axios.get(‘http://localhost:3001/posts’);
    console.log(getDb.data)
    response.render(‘index’, { custdata: getDb.data } );
    console.log(‘active’);
});

More info can be found here

Was this article helpful?

Related Articles

Leave A Comment?