Deploying APIs built via Node.js to IBM Bluemix

In my previous article I described how to use Swagger to document APIs in Node.js applications via a simple hello world sample. Below I demonstrate how to deploy the same sample to Bluemix via Docker and how to use the API Management service to enforce client ids and secrets when invoking the APIs so that API owners can monitor the usage of their APIs.

Deploying Node.js Applications to IBM Bluemix as Docker Containers

First you need to add a Dockerfile to your project’s root directory. The documentation describes how to do this. Since I don’t need SSH I use a simpler Dockerfile.

FROM registry.ng.bluemix.net/ibmnode:latest
COPY . /node
WORKDIR /node
RUN npm install
EXPOSE 9080
CMD ["node", "/node/app.js"]

Since the IBM Containers (Docker hosted on Bluemix) only support specific ports I use the port 9080 instead of 10010 as in the original sample. I also had to change the port in app.js and swagger.yaml. In order to run the application locally you need to invoke the following URLs.

https://127.0.0.1:9080/hello?name=Niklas
https://127.0.0.1:9080/swagger

To build the Docker image and to run it locally invoke the following commands from the root directory.

docker build -t node-swagger-hello-world .
docker run --name node-swagger-hello-world -p 80:9080 -d -t node-swagger-hello-world

After this you can run the sample in our local Docker environment.

https://dockerhost/hello?name=Niklas
https://dockerhost/swagger

In order to push the image to Bluemix invoke the following commands.

cf login
cf ic login
docker tag node-swagger-hello-world registry.ng.bluemix.net/nheidloff/node-swagger-hello-world
docker push registry.ng.bluemix.net/nheidloff/node-swagger-hello-world

To run the sample on Bluemix create a Docker container group.

After this you can run your REST API on Bluemix.

https://node-swagger-docker-hello-world.mybluemix.net/swagger
https://node-swagger-docker-hello-world.mybluemix.net/hello?name=Niklas

Usage of the API Management Service

With the API Management service in Bluemix you can manage and monitor your APIs. In the next part I describe how to enforce a client id and secret when invoking the API so that you can track which applications called which APIs. The API definition can be imported via pointing to the Swagger 2.0 definition above and additional settings can be configured in the dashboard of the API Management service.

In order to invoke APIs applications developers need to register applications.

Applications can subscribe to plans with the APIs they are interested in and test the APIs directly from the developer portals by providing the client ids and secrets.

The post Deploying APIs built via Node.js to IBM Bluemix appeared first on Niklas Heidloff.

Previous

Top Ten Mistakes while Implementing Responsive Web Design

Future of Web Design – Watch out for these 7 Trends

Next