AngularJS 2 as Frontend and Symfony 3 as backend - angularjs

I will start a new project with angularjs and symfony 2.
I just wanna know if my way, how I will realise it, is good.
The AngularJS frontend would be available over https://www.example.com and the backend of symfony would be under https://api.example.com.
So I hope that the routing of every framework would not colidate.
And I have also a available API for the mobile Devices.
Is this a best practice or is it better to use the api under https://www.example.com/api

IMO it is better to create 2 separate projects.
for the api (api.example.com)
for the front-end (example.com)
This way you avoid problems with:
routing (like you point - collisions)
sessions (api do not need sessions at all)
packages - e.g. your api could use symfony 3.1, but your front-end symfony 2.7
easier load balancing (IMO)
see:
Is it better to place a REST API on a subdomain or in a subfolder?

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)

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

Caching for the frontend application

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/

AngularJS app - with Lumen or Laravel?

I am about to build web application consisting of three parts:
Public data-oriented websites for unauthenticated users with geolocation search, ...
Member area (with authentication) for managing the data
Mobile app/apps with the same functionalities
The airbnb.com is a good example of the structure.
Basicaly the thing is to create a server side API which will be shared accross clients.
I definitelly want to use AngularJS for the client side, but I am not sure which of those solutions is better:
Create the API with microframework Lumen and add sessions / authentication / html serving / other services to the Lumen
Create the API with full stack framework Laravel and serve html to AngularJS
Thank you for your suggestions.
You will need a solid api, lumen has all we need to build an api. You can go ahead with option 1 as you can later on migrate to full stack laravel framework, if needed.

Meteor, Laravel RESTful API + AngularJS or Laravel for my next web app

I have a PHP background and I have build several web apps with Laravel (3 and 4). I have also experience of using RESTful APIs in my projects.
My current client have an ERP which is bunch of PHP files. Those files contains about 60K lines of spaghetti code. Client doesn't want to invest more money for developing that system so we decided to rewrite the whole app. I know all the risks about rewrite and I have also read Joel's article (http://www.joelonsoftware.com/articles/fog0000000069.html) so there is no need for refactor or rewrite discussion.
For the new app I have been thinking to build RESTful API with Laravel (4 or 5) and frontend with AngularJS. That was before I tested Meteor 1.0. It is very promising and it would be very nice to use it for this project. But is it suitable for this kind of product?
My client's product is something like this:
No public registration for this app (admin creates all the users)
Complex user permissions (group level permissions and user level permissions, 6 groups)
File handling (images, pdf etc.). Files are used as message attachments.
Big data tables
External API calls
App contains sections like: users, orders, offers, time tracking, sales, reporting, calendars, clients.
So is it wise to use Meteor for this kind project or do you prefer RESTful API + AngularJS combo? I'm hesitating because I'm afraid that in big projects using Meteor the code will becode mess.
I'm working on a feasibility analysis for using meteor on a similar project at Google, and I think Meteor would be great for your project.
Admin user creation - check Houston
REST API - [you don't need one for your own tools]( need to think in Meteor terms. ). Meteor has a much simpler mechanism - Meteor.call and Meteor.methods.
User permissions - see the roles package
File handling - see CollectionFS or search Atmosphere for upload.
External API calls - HTTP.get makes it trivial. See also Atmosphere for specific packages.
Big data tables - see this answer about table widgets
Don't know much about Meteor, but for the Angular variant you can take a look at this POC application using a AngularJS client and a REST Server:
https://groups.google.com/forum/#!topic/angular/Q3GrhAH39AU
http://www.civilian-framework.org/doc-samples.html#crm

Resources