Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,201,325 members, 7,978,040 topics. Date: Thursday, 17 October 2024 at 05:47 PM

Help Understanding Axios - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Understanding Axios (517 Views)

Make Multiple Axios Request In Javascript (vue Js) / Part 2 Of API Building Featuring The Use Of Axios (2) (3) (4)

(1) (Reply) (Go Down)

Help Understanding Axios by benBender: 10:24pm On Apr 10, 2022
I'm currently building a web app, the backend is built with node/express, my database is mongodb while I'm using a templating engine for the front-end (why??) .

The issue am having now is that I want to manipulate the DOM right before data is store in the database.

So I did some research and I found out I need to store my data in a database without reload the page which can be accomplished with axios library.

I having been searching for 3 days now on how to incorporate axios into my code, to say am confuse will be an understatement of the century.
Like I don't even know if I should use it on my server or client side.

Somebody, anybody please help??

@qtguru
@tensazangets20
@airsaylongcome
@DrLevi
@karleb
Re: Help Understanding Axios by devdev: 11:31pm On Apr 10, 2022
benBender:
I'm currently building a web app, the backend is built with node/express, my database is mongodb while I'm using a templating engine for the front-end (why??) .

The issue am having now is that I want to manipulate the DOM right before data is store in the database.

So I did some research and I found out I need to store my data in a database without reload the page which can be accomplished with axios library.

I having been searching for 3 days now on how to incorporate axios into my code, to say am confuse will be an understatement of the century.
Like I don't even know if I should use it on my server or client side.

Somebody, anybody please help??

@qtguru
@tensazangets20
@airsaylongcome
@DrLevi
@karleb
On your nodejs application, i believe you have something called routes, these routes are known as APIs... How you set up these routes determines how axios can interact with them. So you have options like POST, GET, PUT, DELET etc. On the axios side, for example you have a GET route, all you do is axios.get(api).then().catch().... In this case, Axios should be used on your frontend

2 Likes

Re: Help Understanding Axios by Nobody: 11:45pm On Apr 10, 2022
Save yourself the trouble and learn to use a client-side framework. If you want to make database update without reloading the page, you're basically doing what client frameworks are built for and is every indication that you need to switch to using one.

3 days you spent on that was enough to get Vue or Svelte running.
Re: Help Understanding Axios by benBender: 12:55am On Apr 11, 2022
devdev:

On your nodejs application, i believe you have something called routes, these routes are known as APIs... How you set up these routes determines how axios can interact with them. So you have options like POST, GET, PUT, DELET etc. On the axios side, for example you have a GET route, all you do is axios.get(api).then().catch().... In this case, Axios should be used on your frontend

Thanks boss for taking time to answer me.
Since I'm to use it on the client side, I require/import it but I'm getting an error that it's not define.

What I'm I doing wrong.

Re: Help Understanding Axios by benBender: 12:59am On Apr 11, 2022
DrLevi:
Save yourself the trouble and learn to use a client-side framework. If you want to make database update without reloading the page, you're basically doing what client frameworks are built for and is every indication that you need to switch to using one.

3 days you spent on that was enough to get Vue or Svelte running.

Thanks boss, I having been hearing good reviews about svelte I will soon check up on it .
Re: Help Understanding Axios by devdev: 1:55am On Apr 11, 2022
benBender:


Thanks boss for taking time to answer me.
Since I'm to use it on the client side, I require/import it but I'm getting an error that it's not define.

What I'm I doing wrong.
Ok so for template engine on Nodejs, you dont need axios. You just need to install EJS so you can communicate HTML and EXPRESS using <% %>
Re: Help Understanding Axios by Karleb(m): 6:36am On Apr 11, 2022
Just a simple YouTube search will save you this stress.
Re: Help Understanding Axios by drakenyoon: 6:49am On Apr 11, 2022
ui8oi
Re: Help Understanding Axios by benBender: 11:05am On Apr 11, 2022
Karleb:
Just a simple YouTube search will save you this stress.

Boss where, I don comb YouTube still I no see anything
Re: Help Understanding Axios by Karleb(m): 11:43am On Apr 11, 2022
benBender:


Thanks boss for taking time to answer me.
Since I'm to use it on the client side, I require/import it but I'm getting an error that it's not define.

What I'm I doing wrong.

Try window.axios = require('axios') in your main js file.

So you can use it anywhere without importing it.

But then, do you have it installed? You could use fetch without installation though.
Re: Help Understanding Axios by peterincredible: 12:39pm On Apr 11, 2022
Bros save yourself the stress and use the JavaScript fetch() for any request you want to make and probably to add spice to it use alpine.js for handling simple Dom manipulation without much stress
Re: Help Understanding Axios by nahoasameirax: 12:48pm On Apr 11, 2022

Re: Help Understanding Axios by Millz404(m): 1:08pm On Apr 11, 2022
Axios is a way to communicate with ur server from the frontend and get response from the server in json format.
On the back end you can also use it to communicate with external Api's and get response from them.

You have different methods post, put, patch delete, and get. You normally have a route on ur backend which the axios request will go through to your backend to execute a code which you have written and get response from the code. The axios request from your front is already waiting for that response.

When it comes back in json format, you can use the information to display to your user. For instance you can send a get request to fetch user information through the get route. When the code in the backend fetches the information from the database it sends it back. Your axios response block in the frontend collects it back and you can then use that information how you want in the frontend.

You should explore frontend frameworks like Vue and react. Axios and other tools like it are an integral part of modern development.
Re: Help Understanding Axios by qtguru(m): 2:21pm On Apr 11, 2022
peterincredible:
Bros save yourself the stress and use the JavaScript fetch() for any request you want to make and probably to add spice to it use alpine.js for handling simple Dom manipulation without much stress

Gbam use Fetch axios is just another layer on XHR/Fetch API

(1) (Reply)

HELP! COUSERA Is Requesting For A Government Issued ID To Give Me My Certificate / Devs, How True Is This Funny Comment I Heard About CSS And React / Are You A Database Admin? Take This Survey And Win $700

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.