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
-
To create a template, go to IBM Cloud Functions in the console and click ‘Start Creating’.
-
Click ‘Deploy Template’.
-
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.
-
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’.
-
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.
-
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=Austin
https://{APIHOST}/api/v1/web/{QUALIFIED ACTION NAME}?location=Miami
-
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.
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