Back to blog home page

How to Build an Angular App with Server Side Logic

Posted by on May 26, 2015

Overview

Actions are a powerful tool that allow you to perform customized tasks when a number of different types of events occur within your application. They provide a great alternative to server-side custom code, and can add a lot of flexibility to how your application interacts with outside services. Below we’re going to look at the types of actions that Backand offers application developers, and how they can easily be used.

Server-Side Activity in a Front-End App

One of the challenges facing Angular developers focused on front-end development is what you need to do when you hit the limits of what the front-end has to offer. Many calls that you might like to make from your JavaScript might expose security issues, such as specific formats for requests to external vendors like PayPal, that leave you vulnerable to hackers who are looking for any way to hijack your application. The traditional solution to this has been to move the calls themselves server-side, which is a lot harder to gain access to than the JavaScript code running your website. However, having custom server actions requires building up the surrounding infrastructure to handle web requests, trigger the actions, handle the responses, and perform authentication – among a number of other actions you need to control for – all just to send a single server-side call.

With Backand’s server-side actions, you completely sidestep the need for all of the setup, implementation, and deployment headaches you would have with a custom server-side framework like Rails or Django. It allows you to do things that would typically demand custom server code – such as authenticating with a third party vendor, or sending sensitive payment data – without having to build the server infrastructure. By providing simple hooks into Backand’s API for your back end, you can quickly add new actions that can do anything from sending a simple email all the way up to running custom JavaScript that can perform any arbitrary action you like – all behind the server-side call to Backand!

Triggers

Actions are activated via triggers in your application. Generally speaking, there are two types of action triggers in Backand – database-related triggers, and “On Demand” triggers. Database triggers fire under certain conditions when your application interacts with your database. You can add custom triggers to each of the standard database actions that update the database – record creation (Create), record updating (Update), and record deletion (Delete). Furthermore, you can assign your actions to occur either before the action takes place (such as “Before Update”), while the action is taking place as part of the same transaction (such as “During Create”), or after the action has completed (such as “After Deletion”). Through clever use of these actions, you can create a very complex database experience with a deceptively simple front-end.

On Demand triggers, on the other hand, happen whenever you like. These are associated with a specific table, and are performed in the context of a row via a simple call to an associated URL. These actions operate within the context of the provided row, allowing you to perform any custom actions you need to on that specific object. This allows you to build out a true API, providing the hooks for many custom server actions that would often need a framework surrounding them.

Types of Actions

Once you’ve selected an appropriate trigger, you need to select a type of action to perform. Backand currently offers three types of actions – Send an Email, Execute Custom JavaScript, and Execute Custom SQL. Send an Email, as the name implies, simply sends an email whenever the trigger in question occurs. You can use the subject of the trigger as a local variable, inserting details into the message as you desire. Execute Custom JavaScript allows you to write a custom JavaScript function that will execute during the trigger, all within a server context. This allows you to perform sensitive communication without exposing vital details to potential attackers. Finally, Execute Custom SQL allows you to run a custom SQL script when the trigger is encountered, performing additional bookkeeping or updating related tables based upon the action performed. With these three action types, you should be able to perform many highly complex interactions without needing to worry about maintaining a back-end server to manage them.

Video Tutorial

Actions are pretty easy to use with Backand.  Watch this video tutorial and see for yourself.

Conclusion

One of the common concerns with outsourcing the back end of an application is “What happens when I need something more from the server?” With Backand’s actions, you have the opportunity to perform a number of different types of actions at several highly-configurable trigger points, and all in the context of your application’s server! This can allow you to implement sensitive web calls to third parties, maintain complex analytics back-ends, and protect your sensitive data from attackers – all with a few clicks in Backand’s application dashboard. While actions are not ideal for all situations, they should suffice for the vast majority of server-side activity that web apps most commonly need.

Sign up for free and start creating your app today.