3 ms·
Ask HN: How do I consume an API with the lowest JavaScript overhead?
How do I consume an API without making a full-blown JS SPA. I need the website to be light-weight and fast loading. However, all relevant content is going to come from an API. How do I do this in the most lightweight way possible?
I have very little JS experience. I mostly work with Python on the backend.
- aidos 7y agoThe API already exists? The very simplest thing to do in 2020 (assuming modern browsers) is to use fetch: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/U... Having said that, you probably still need to think a little about auth etc. Depends on what you're doing. If it's all internal then it's fine but otherwise you need some notion of who the caller is and they need to send something with each request that's checked on the python backend.
- dhruvkar 7y agoThe API is in process of being built. At the moment, it's internal, but might be something I open up later. re: auth Should I be using oAuth? or is there something simpler with 80% the security?
- aidos 7y agoDo you have / need user accounts?
- dhruvkar 7y agoYes eventually. At the moment, I'll be the only consumer of this API.
- aidos 7y agoThen I wouldn’t worry about any of that. You could put an htaccess file in front of the api so you have to enter a known in / pw - but that’s handled by the browser. Just do the absolute simplest thing you can do until you have more complicated requirements. Edit see other comment (don’t want the thread to get unreadably deep!)
- aidos 7y agoDo you have interactions to worry about or are you just loading some data to display on the page once with no further behaviour?
- dhruvkar 7y agoJust loading data to display on the page. Thanks for all your help. I see you write takeoff software -- that's pretty close to what we do. We do the supply for builders.