From new account to running code in 5 minutes with serverless Templates

5 min read

By: Belinda Vennam

From new account to running code in 5 minutes with serverless Templates

Using Templates for IBM Cloud Functions, you can start building serverless apps in less than 5 minutes. Literally.

What is a Template?

IBM Cloud Functions has just released a catalog of Templates to help you jump start your next serverless application. Templates can be any combination of Actions, Triggers, and Sequences connected together to form a solution. With Templates, you can quickly and easily create actions and start coding right away. Some of the Templates will require service instances from IBM Cloud. There are different Templates available, from printing new item information whenever a new item is added to a Cloudant database to setting up a periodic trigger connected to slack.

Once you’ve deployed the Template, make your own edits to the provided code, and it will quickly become your own! You can go check out the catalog of available Templates or follow along with the instructions for creating your first Template below.

Deploying Templates in IBM Cloud Functions

  1. To create a template, go to IBM Cloud Functions in the console and click ‘Start Creating’.

  2. Click ‘Deploy Template’.

  3. Select the Template you would like to create. For now, let’s try out the ‘Get HTTP Resource’ template. This template will deploy an action to fetch an external resource — in this case the Yahoo Weather API — and then return data. You might want to use a pattern like this when building a backend for a web application, especially if the resource you’re accessing needs an API Key or credentials that you don’t want exposed in your front end app or if the resource is not CORS aware.

    Deploying Templates

  4. The action is enabled as a Web Action, which allows it to be invoked via a URL without an authentication key. Check out the code, and then click ‘Deploy’.

  5. Once you’ve deployed the action, click the ‘Endpoints’ tab and copy the Web Action public URL. You can now paste that URL into your browser to see this action working.

  6. If you don’t pass in a parameter, the action will return the weather for Vermont since that is set in the code as the default. You could also provide a parameter with a location to get the weather for a different location:https://{APIHOST}/api/v1/web/{QUALIFIED ACTION NAME}?location=Austinhttps://{APIHOST}/api/v1/web/{QUALIFIED ACTION NAME}?location=Miami

  7. You should see the weather for your chosen location!  The action received the request from your browser, then made a call to the weather API, and returned with a response.

    weather API

What’s Next?

We’re excited to see this catalog grow as we continue to add Templates that are useful to you. Is there something specific you would like to see created as a Template? Feel free to share in the comments below, or by reaching out directly to our team!

Learn more about IBM Cloud Functions

 

Be the first to hear about news, product updates, and innovation from IBM Cloud