Saving data from 3rd party API to CouchDB using AngularJS - javascript

I have a working frontend app build with AngularJS.
It interacts with a couple of 3rd party APIs and is getting data without a problem.
The next step of the app would be to store this data into a CouchDB everytime a search is made. I want to build my own db little by little and to eventually rely on it and not on the 3rd party API (e.g., the app first makes a query to my database, if it doesnt find what's needed, takes it from the 3rd party API, displays it on the frontend but it also saves it on my database, so next time the same search is conducted, the results will come from my resource).
Do I need to use nodejs and some module (express, nano, etc) or can I rely only on AngularJS to write data to the DB?

CouchDB has a simple REST interface that you can call directly from AngularJS. There's a Angular module for it as well called CornerCouch

Related

Getting data from ERP in mobile APP how to do it properly?

I’m building an app and I need to communicate with the ERP that uses webservices and is most of the time reliable.
My backend is a Graphql api I’m wondering how should I get the data from ERP?
The options I’m considering:
Fetch the data from ERP on every request from the app and save it to my separate DB.
Create a cron job and copy the data every X time to separate DB.
Create a microservices server and update the data in the queue on every request.
Or is there another solution I’m not seeing?
The problem is that the ERP web services are not as reliable as my separate DB.
Right now I have the 3 packages the backend the server that gets the data from EPR and react native client.

Database & Caching Setup to Handle Large Amounts of Data from 3rd party API?

I currently fetch business's historical sales data from a 3rd party api, and this data is needed for the user's entire life with my web app. I also need ongoing updates from the same 3rd party api for new sales data each day.
I am currently able to handle business's with a few thousand objects in their historical data, but I need to scale to handle business's with 100,000+ objects of historical data and 100+ new objects added daily.
Every time a user loads the app, I currently run a bulk operation to get all data from the 3rd party api. I am not currently storing any of the 3rd party api data in a database.
Caching for my API calls is currently done locally with apollo client, I use MongoDb for saving general user provided inputs, and Redis for managing sessions. I am using Node JS, Next JS, and Heroku as well.
To handle 100,000+ objects at installation and 100+ new objects daily per user from the 3rd party api (all data is vital), how should I approach storing and caching the api data?

Secure access to 3rd party API from a Javascript app

I am creating a web app in Angularjs which displays data from a 3rd party API (json). This is not a free API, I have to pay based on the amount of calls made.
I am given an API key which I call like this:
https://apiservice.com?key=1234567&p1=x&p2=y
I want to ensure that my api key is used only by my web app, so I created a proxy on my server. Now my angular app calls my server like this:
https://myserver.com/myapiproxy/?p1=x&p2=y , the server makes the call to the api using the key that is kept on the server, and returns the json data to the client. This way the key is kept secret.
However there is currently nothing to stop somebody else from calling "myapiproxy" and get the data.
Is there a way to ensure that only my app gets the data and that others can not make calls to the api on my expense?
I searched for a few hours and I couldn't find a truly secure answer. HTTP referer is not a good answer because it can be easily spoofed.
Take a look at JSON Web Tokens - https://jwt.io/
It is a good way to secure your calls. It has angular module - https://github.com/auth0/angular-jwt
When user loads your app you can provide a token jenerate on the backend and store it in local storage.
Than on each api call you can check if this token is authentic.

Web app architecture for third party API calls

I'm building a simple search engine that takes a user submitted search query as input and outputs a list of appropriate search results. Search queries ultimately get sent to a third party API, which does the heavy lifting of generating search results.
There are 2 ways I can handle this workflow:
My server takes user requests, queries the third party API, and returns results to the user
or
Shifting this responsibility to the client-side; the client queries the third party API directly.
What are some considerations when choosing between these 2 methods?
Using option #1 gives you a few advantages like:
You have one API for one view. It brings some clarity in your architecture.
You might have a lot of pages/windows/whatever using same search API. If third-party API changes or moves to another domain or does something which makes you change your code, you can fix only one API method on your server instead of fixing all your clients.
You can perform some additional changes with your search query like translating it if third-party search engine can't do it itself. Formally, you can implement some additional logic.
Using option #2 reduces the burden on your server.

AJAX with Django in RESTful environment

I am new in restful programing. I have a django website, my goal is to load part of the website asynchronously.
By default what I do now is:
call a url (e.g. localhost:8080/index) -> Routes the Django view -> View takes data from database (mongodb if you are curious) -> View gets the template -> Render all together and send back to browser
What I want to improve is:
When I have opened a url e.g. localhost:8080/index and I trigger an event (e.g. click a <a>) to send a request to my database and load other data.
My question:
What is the step I have to do to bridge the javascript / ajax with my mongodb safely?
Additionally I am considering to use a front end MCV framework (I think about backbone/I have limited knowledge as well) to handle the front-end requests. E.g. localhost:8080/index#2 returns objects with id : 2 of my database.
You should look at the following rest API frameworks for django. They will help save you a lot of time.
Django Tastypie
Django Rest Framework
I have used both and personally like tastypie better. Once you have integrated one of these in your project you can use any front end javascript framework like angularjs or backbone or even not use one and simply make a call to the resource url to get the data via ajax.

Categories

Resources