Wednesday, January 18, 2017

Context Path Routing of Apps and Services in Bluemix

Context Paths for Bluemix Apps
As I mentioned in my post yesterday about simplified deployment of complex apps, I have been working on a sample for Context Path Routing to be used with IBM Bluemix. But what are context path routes and what does the sample do? Here are the details.

Cloud Foundry introduced Context Path Routing last year. Until then there was the requirement that each app (or service) was served from its own hostname. Now, apps can share a host with each app being served from a specific path on that host. Here are two examples:

  1. When building a larger website, there could be several so-called microsites embedded. With Context Path Routing it is possible to serve, e.g., example.com from one web app and example.com/user-management or example.com/news from other apps. All these apps could be written in different programming languages such as Node.js, Python, Java and others. 
  2. For a more complex microservice-based app, following the principles of the Twelve Factor App, there could be several (backing) services involved. The app and each would require their own hostname. With Context Path Routing the app could use app.mybluemix.net and services could be served from app.mybluemix.net/service1, app.mybluemix.net/service2, etc.
So how could you use the new routing feature? There are several Cloud Foundry CLI commands related to routing. They allow to specify an additional path for application routes. Manifest files also have optional route properties that could be set. To get started, take a look at my Context Path Routing sample on GitHub for details. It has two small apps written in Python and Node.js that share a host using specific paths. The apps can be deployed with a single command and allow to experiment with context paths. The "What this samples does" section gives you some ideas.