DEV Community

Cover image for Svelte 3 - How to connect your app with a Rest API Axios

Svelte 3 - How to connect your app with a Rest API Axios

Luis Castillo on June 16, 2020

Hello everybody, continuous with the Svelte post series, Today I want to share one technique that normally use to connect my Web applications with ...
Collapse
 
hydracorey profile image
Corey Vincent

What did you mean by:

const axiosAPI = axios.create({
  baseURL : "https://pokeapi.co/api/v2/" // it's not recommended to have this info here.
});
Enter fullscreen mode Exit fullscreen mode

Are you just suggesting we get the 'baseURL' constant from somewhere more global, or that there's a way to secure/hide that value? I was under the impression the front end can be seen by pretty much anyone...

Collapse
 
rubendutchtelco profile image
RubenDutchtelco

You are correct about the fact that all front-end code is always visible to the end user.

I think the recommended method the author is referring to is a .env like file (npmjs.com/package/dotenv). Which does not hide the values but makes them more variable and easier to change without having to alter your code.
You might want your front-end connecting to different base URL's depending on what environment it is running (dev, staging, prod).

Collapse
 
hydracorey profile image
Corey Vincent

Thanks for the response. Your points make sense.

Thread Thread
 
bd_perez profile image
Bruno Pérez

Exact, the base url of the API is not a sensitive information. You can track all API calls with your browser devtools anyway

Collapse
 
faustineshaw97 profile image
faustineshaw97

Hi. Hope you are doing well. I tried using books for JavaScript but I realised that perhaps watching someone else code and following along like in a video tutorial may be more helpful while learning JavaScript. Any free video tutorials/courses like on YouTube you know of that teach JavaScript from scratch well, ie from basics, and then moves on to like equipping me to build projects myself? Thanks. Also I might need to relearn HTML and CSS from the beginning, which YouTube tutorials could you point me towards?

Collapse
 
joshuawoodsdev profile image
JoshuaWoods

Dude this is good I feel like this is missing something when I started it I didnt see anything. what about the app.js?