Caching for the frontend application - angularjs

I am working on a web application that uses Spring MVC framework and hibernate for the backend and using DAO classes and DTOs for persistence. After entity fetch the dto is being sent as a JSON to the frontend that uses angularJS for the front end.
I am asked to add caching to the frontend application.The dB call is to be avoided if the the request is hit again within some time frame. Please suggest me how i can implement this. Also please tell me some different ways how caching can be implemented to make frontend perform better.
Thanks,

You should use EhCache here some tutorials
http://www.mkyong.com/spring/spring-caching-and-ehcache-example/
or
https://amitstechblog.wordpress.com/2011/11/08/configuring-ehcache-with-jpa-hibernate-spring/

Related

Secure webapp with Django and React

I'm experimenting with these 2 technologies to make a secure web app [Currently learning React (60%) and Django (<50%). This is intended to be like a medical database, so doctors and nurses enters their patients' information. They need to login obviously. I wanted to implement React-based UI (And not using the classic method to create views from django), so I've found many tutorials just like this one:
https://www.digitalocean.com/community/tutorials/build-a-to-do-application-using-django-and-react
It basically turns Django into a restAPI, and then the React frontend uses axios to retrieve data from the endpoint. Sounds not bad at all (comparing to the native method of rendering data in a webpage from Django), but the problem is that I have no idea on how to make this secure, you know, Django provides an auth system, which is pretty good and secure, I have to say, but in a project with this structure, the auth needs to be done in React, so there many questions appear:
To start with, is it a good idea to make a project of this structure? (If no, then what could be a good one)
If it's a yes, how can I protect the API so only logged in users can interact with it? (What mechanisms to ensure protection)
Yes, this is absolutely a good idea to separate the client application and the backend server application.
You can access the backend through the rest api basically with any frontend framework/app/script.
Customers are able to extend their own applications with the abilities of your backend service.
You can create multiple different frontends that use the same backend or different parts of the same backend via the rest api (multi-branding, reselling). Or you can just swap the frontend framework every second year to a new one.
It's also easier to create different automations by using the rest api.
And the list goes on.
For django rest api auth I would recommend Token Authentication which is already included in the Django REST Framework and for React use this tutorial for implementing the login and the token handling.
And don't forget to use TLS on your servers, and create API documentation. (Example)

How to use API as backend in ionic mobile app development?

I am having a web application built using JAVA spring which has API feature to read and write into database.
Now i have to develop an ionic mobile app for the same application. How to read and write data into database.
I know Firebase and other alternatives can do the job.
But i need my own API code(written for web app) to be used. Is there any way to achieve that?
I guess calling the respective API when the web application is live is achievable.
But how can i achieve that while developing(When the web app is under construction)
Well depending on how you set up the API this could become quite difficult.
You're saying/guessing that you can call the API when the webapplication is live. This makes me assume you've created a REST API? Or did you create a Spring MVC application?
If the webapplication is directly linked to your Spring application (f.e. going to localhost:8080/my-profile shows a page (not JSON) of your profile) then I'm not sure if you can achieve the above mentioned target.
If you get a JSON response, or are somehow able to retrieve it from the webpage, you can just simply call (in typescript:)
this.http.get('http://localhost:8080/my-profile').map(response => console.log(response.json() );
Else, you probably will have to create a basic REST API (check out Spring boot for a 5 minute setup) and provide it, either with hardcoded data or connect it with your database.

Angular JS and Web API Architecture

I have to prepare an architecture with following technologies:
Angular JS 1.5
MVC 5.0/Web API.
EF 6.0
Is it a good option to have a single web project which has angular JS and Web API.
We need to expose web api's to other third party vendors. So, we are thinking to create a separate web api project as a separate project. Need your inputs.
Thanks,
Dhannajay
You can have a lot of options to define the architecture, but to answer your questions, I think is better have separate projects in this case for the following reasons:
You can change the front-end without touch any in the api system (web api) and viceversa
You can scale both sites or only one, maybe, the front-end goes well, but you need more power in the web api, go ahead and scale only the api.
you can do this (like here)
API: your api front end
Core: business logic/EF
MVC: html/mvc/angularjs
DTO: classes/models

Angular + Apache CXF for RDBMS access or Angular + Spring MVC?

I have to write a simple web-application which basically fetches data from RDBMS, does some computations on the data and displays the results on screen.
There is a reference application from which I need to re-use components.
I have come up with two options -
First - To use Angular.js for creating the views which calls REST based web services exposed by the server side using Apache CXF. REST based services hit the DB, process the data and return it to the client side.
Second - To use Angular.js for creating the views which calls Spring MVC based controllers. Controllers hit the DB, process the data and return it to the client side.
I only have experience in Spring MVC + tiles based JSP for views, so, I was initially inclined with the second approach, but upon further thinking, I think that the first approach is better since I can let the application be driven from the client side for flow routing and let the client side be dependent on REST bases services rather than being tied up to the Spring MVC framework.
it will really help me if somebody can provide me some more inputs... thanks in advance...
Working with Rest expose your services, to any level including your application as well. If in future anyone else needs you services, you can easily expose it using REST. So in my view, working with REST is more beneficial and rest depends on your business case.
Moreover you can combine both approaches. use REST to expose your services and MVC for separation of concerns and avoiding tightly coupled data and business logic.

backbone.js and the need of a back-end engine

reading this days about backbone.js (documentation, examples, etc), and as far as i have understood, this framework lets you code directly on the front-end, almost all the back-end engine, since you can structure a MVC architecture. You can create your data model, controllers, etc.
My question is: if you already have the MVC architecture built on the Front-End (engine), you just need a DataBase (SQL) in the cloud from where you can fetch or store data, why do you need a back-end engine (RoR3,Java,etc) to persist document data?
thanks in advance
You are confusing two different meanings of front end, the model in the backbone framework is not able to connect to a database directly, this model are designed to connect to an API (that would be your backend) that is connected to a database
Things you still need to do on the server:
authentication
authorization
data sanitation and filtering
Possiby
interact to third parties
business logic that involves modules other than UI
etc.
Front-End MVC frameworks (Backbone, Angular, etc) all rely on a backend service to provide the data that, say Backbone, would then use as its model.
You could have an entire MVC pattern on the backend that accepts requests and spits out some JSON for a frontend MVC framework to use.
If you just want a database without creating a server, I would recommend using Google FusionTables - but you need OAuth and maybe even ClientLogin (depending) on top of that.
Because as far as I know Backbone works with RESTful services and it needs a server to handle the requests:
get: to list data from the db
post: to add new stuff to the db
put: to update current data
delete: to remove data from the db.
.. and also perform all sorts of server related stuff if you like
For instance I'm using Restful server based on Code Igniter to handle that stuff. From there you can choose the DB you want to work with. I already tried using MySQL and MongoDB

Resources