Skip to content

Added azure-node-http example 🎉 #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
| [Aws Function Compiled With Babel](https://github.com/serverless/examples/tree/master/aws-node-function-compiled-with-babel) <br/> Demonstrating how to compile all your code with Babel | nodeJS |
| [Aws Github Webhook Listener](https://github.com/serverless/examples/tree/master/aws-node-github-webhook-listener) <br/> Extend your github repositories with this github webhook listener | nodeJS |
| [Aws Iot Event](https://github.com/serverless/examples/tree/master/aws-node-iot-event) <br/> Example on how to setup a AWS IoT Rule to send events to a Lambda function | nodeJS |
| [Aws Rest Api Offline](https://github.com/serverless/examples/tree/master/aws-node-rest-api-offline) <br/> Serverless REST API with DynamoDB and offline support | nodeJS |
| [Aws Rest Api Offline](https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb-and-offline) <br/> Serverless REST API with DynamoDB and offline support | nodeJS |
| [Aws Rest With Dynamodb](https://github.com/serverless/examples/tree/master/aws-node-rest-api-with-dynamodb) <br/> Serverless CRUD service exposing a REST HTTP interface | nodeJS |
| [Aws Scheduled Cron](https://github.com/serverless/examples/tree/master/aws-node-scheduled-cron) <br/> Example of creating a function that runs as a cron job using the serverless `schedule` event | nodeJS |
| [Aws Scheduled Weather](https://github.com/serverless/examples/tree/master/aws-node-scheduled-weather) <br/> Example of creating a function that runs as a cron job using the serverless `schedule` event through pulling weather and sending an email daily. | nodeJS |
Expand All @@ -56,6 +56,7 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
| [Aws Rest With Dynamodb](https://github.com/serverless/examples/tree/master/aws-python-rest-api-with-dynamodb) <br/> Serverless CRUD service exposing a REST HTTP interface | python |
| [Aws Scheduled Cron](https://github.com/serverless/examples/tree/master/aws-python-scheduled-cron) <br/> Example of creating a function that runs as a cron job using the serverless `schedule` event | python |
| [Aws Simple Http Endpoint](https://github.com/serverless/examples/tree/master/aws-python-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with python | python |
| [Azure Node Simple Http Endpoint](https://github.com/serverless/examples/tree/master/azure-node-simple-http-endpoint) <br/> An example of making http endpoints with the Azure Functions Serverless Framework plugin | nodeJS |
| [Openwhisk Node Chaining Functions](https://github.com/serverless/examples/tree/master/openwhisk-node-chaining-functions) <br/> Example of chaining function calls using sequences and the sdk. | nodeJS |
| [Openwhisk Node Scheduled Cron](https://github.com/serverless/examples/tree/master/openwhisk-node-scheduled-cron) <br/> Example of creating a function that runs as a cron job using the serverless schedule event. | nodeJS |
| [Openwhisk Node Simple Http](https://github.com/serverless/examples/tree/master/openwhisk-node-simple-http-endpoint) <br/> Example demonstrates how to setup a simple HTTP GET endpoint with OpenWhisk. | nodeJS |
Expand Down
3 changes: 3 additions & 0 deletions azure-node-simple-http-endpoint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
functions
.serverless
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider configuring your editor to add a newline at the end of the file.

27 changes: 27 additions & 0 deletions azure-node-simple-http-endpoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Simple HTTP example

In this example, we deploy an HTTP Node.js Azure Function. This sample show you how to read properties off of a query string or the request body, then set a result back to Azure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "This sample shows ..., then sets ..."


See the [Azure Functions Serverless Plugin docs](https://www.serverless.com/framework/docs/providers/azure/) for more info.

## Setup

1. We recommend Node.js v6.5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is given by Azure, not really something the user can choose.

2. Install the serverless framework - `npm i -g serverless`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be assumed to be installed.

3. Install the dependencies of this example - `npm i`

## Deploying

To deploy, set up your [Credentials](https://www.serverless.com/framework/docs/providers/azure/guide/credentials) and run

```bash
serverless deploy
```

## Invoking

Once deployed, run

```bash
serverless invoke -f hello
```
15 changes: 15 additions & 0 deletions azure-node-simple-http-endpoint/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

module.exports.hello = (context, req) => {
context.log('JavaScript HTTP trigger function processed a request.');
const res = {};
if (req.query.name || (req.body && req.body.name)) {
// status: 200, /* Defaults to 200 */
const name = req.query.name || req.body.name;
res.body = `Hello ${name}`;
} else {
res.status = 400;
res.body = 'Please pass a name on the query string or in the request body';
}
context.done(null, res);
};
14 changes: 14 additions & 0 deletions azure-node-simple-http-endpoint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "azure-node-simple-http-endpoint",
"version": "0.1.0",
"description": "An example of making http endpoints with the Azure Functions Serverless Framework plugin",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "serverless.com",
"license": "MIT",
"dependencies": {
"serverless-azure-functions": "^0.1.0"
}
}
29 changes: 29 additions & 0 deletions azure-node-simple-http-endpoint/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
service: azfx-node-http

provider:
name: azure
azureSubId: YourAzureSubscriptionID
azureServicePrincipalTenantId: servicePrincipalTenantId
azureservicePrincipalClientId: servicePrincipalClientId
azureServicePrincipalPassword: servicePrincipalPassword
location: West US

plugins:
- serverless-azure-functions

package:
exclude:
- node_modules/**
- .gitignore
- package.json
- .git/**

functions:
hello:
handler: handler.hello
events:
- http: true
x-azure-settings:
authLevel : anonymous


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider configuring your editor to add a newline at the end of the file (or simply remove the trailing spaces after the last newline).