Skip to content

Commit 9b54b38

Browse files
authored
Merge pull request #98 from christopheranderson/azure-examples
Added azure-node-http example 🎉
2 parents a61f49e + 9e25f7c commit 9b54b38

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
4242
| [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 |
4343
| [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 |
4444
| [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 |
45-
| [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 |
45+
| [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 |
4646
| [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 |
4747
| [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 |
4848
| [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 |
@@ -56,6 +56,7 @@ Have an example? Submit a PR or [open an issue](https://github.com/serverless/ex
5656
| [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 |
5757
| [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 |
5858
| [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 |
59+
| [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 |
5960
| [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 |
6061
| [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 |
6162
| [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 |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
functions
3+
.serverless
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Simple HTTP example
2+
3+
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.
4+
5+
See the [Azure Functions Serverless Plugin docs](https://www.serverless.com/framework/docs/providers/azure/) for more info.
6+
7+
## Setup
8+
9+
1. We recommend Node.js v6.5.0
10+
2. Install the serverless framework - `npm i -g serverless`
11+
3. Install the dependencies of this example - `npm i`
12+
13+
## Deploying
14+
15+
To deploy, set up your [Credentials](https://www.serverless.com/framework/docs/providers/azure/guide/credentials) and run
16+
17+
```bash
18+
serverless deploy
19+
```
20+
21+
## Invoking
22+
23+
Once deployed, run
24+
25+
```bash
26+
serverless invoke -f hello
27+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
module.exports.hello = (context, req) => {
4+
context.log('JavaScript HTTP trigger function processed a request.');
5+
const res = {};
6+
if (req.query.name || (req.body && req.body.name)) {
7+
// status: 200, /* Defaults to 200 */
8+
const name = req.query.name || req.body.name;
9+
res.body = `Hello ${name}`;
10+
} else {
11+
res.status = 400;
12+
res.body = 'Please pass a name on the query string or in the request body';
13+
}
14+
context.done(null, res);
15+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "azure-node-simple-http-endpoint",
3+
"version": "0.1.0",
4+
"description": "An example of making http endpoints with the Azure Functions Serverless Framework plugin",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "serverless.com",
10+
"license": "MIT",
11+
"dependencies": {
12+
"serverless-azure-functions": "^0.1.0"
13+
}
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
service: azfx-node-http
2+
3+
provider:
4+
name: azure
5+
azureSubId: YourAzureSubscriptionID
6+
azureServicePrincipalTenantId: servicePrincipalTenantId
7+
azureservicePrincipalClientId: servicePrincipalClientId
8+
azureServicePrincipalPassword: servicePrincipalPassword
9+
location: West US
10+
11+
plugins:
12+
- serverless-azure-functions
13+
14+
package:
15+
exclude:
16+
- node_modules/**
17+
- .gitignore
18+
- package.json
19+
- .git/**
20+
21+
functions:
22+
hello:
23+
handler: handler.hello
24+
events:
25+
- http: true
26+
x-azure-settings:
27+
authLevel : anonymous
28+
29+

0 commit comments

Comments
 (0)