In this article I want to show how to use the “Reactive Events” library RxJS to handle asynchronous event processing in AngularJS2.
The RxJS libraray is taking the concept of promises even further with the interface Observable, which is a combination of a Promise and an Iterator. To be precise, an Observable describes a channel to receive an arbitrary number of events asynchronously over time.
Angular2 adapts this paradigm for all major interactions, as all asynchronous actions can be described by Observables:
In the past we often had some software (e.g. web application inside an application server) that needed to be deployed on multiple servers, different stages (development, staging, production) and even on some machines hosted by a customer, but managed by ourselves.
To help with setting up the server and configuring the software, the container management tool Docker made a lot of this tasks easier by providing a defined and stable platform for application deployments.
The purpose of Docker
So, what are the aims of Docker and how can it help your deployment?
First of all, when you try to install and deploy your software on a linux server, there are a lot of uncertainties and variable conditions, that can influence your installation:
Used operation system distribution (CentOS, Ubuntu, Debian, or even Gentoo?)
Installed libraries and version of the libraries and tools (is java environment available? in which version by which provider in which path?)
System settings, like character set and time zone
Blocked ports by other services (is port 80 already taken? how to handle another server software, that also needs this port?)
When you are building applications or libraries in the Scala programming language, you will most likely use a tool like “SBT” (Scala Build Tool) or “Lightbend Activator” (which is an extended distribution of SBT) to configure, build and package your project. These tools support automatic dependency management for your project.
Like in almost every build system, SBT allows you to define library dependencies which are resolved automatically, so you don’t have to download and package required libraries by yourself.
Currently SBT can handle a lot of repository types, including Ivy and Maven repositories, which gives you instant access to all libraries available in the Maven universe.
Recently one of our customers faced the challenge of fixing a production error in his desktop client application. Using SVN this may be a time consuming and error-prone task. So I held a workshop about Git and GitFlow.
Our customer’s application is deployed in different versions. It may also be deployed to different customers. With a different set of features. This scenario seems quite common nowadays. However a lot of software companies are not ready to tackle this problem.
Git – a distributed Version Control System
The easiest and most effective way to support this scenario is to implement a workflow based on Git. Therefore I held a workshop about Git and GitFlow.
If you make a request to a REST service and are not logged in, by default ASP .NET 5 Identity returns a 302 Redirect to login page. This is great if you are visiting the URL of a controller directly. If you make an Ajax request to a specific REST API and are not logged in however, you are also redirected to the login page and instead of the content of the API you will get the content of the login page itself. Probably without even noticing it right away.
So in instance of API calls I would prefer a 401 Unauthorized status code, e.g. $http requests using AngularJS. Here only the Ajax call itself gets redirected, but the URL of the browser remains the same. This means you won’t see that there is an “authentication problem” and you are not redirected to the login page.
In this article I will demonstrate how to restrict controller access to users that have already logged in. In the second part I will show how to do authentication using a REST Controller.
In order to restrict access to a Controller you only have to add the Authorize Attribute to Controller as shown below.
After adding this Attribute all consumers of this REST service that are not logged in will get a status code 302 redirect to the default login location. I will demonstrate how this location and behavior can be modified in a future article.
In my Angular2 application I want to be redirected to the login page whenever I get a 401 response during an Ajax call. Therefore I want to intercept all Ajax calls and check for the response code. In addition to that I also want to set a couple of default request headers for each Ajax call. The code below shows an interceptor for angular2 http requests.