Skip to content

Commit 8ee1d40

Browse files
authored
Merge pull request serverless#367 from pramonow/added_query_example
Added query param example in http get
2 parents 691f59a + 796d2fb commit 8ee1d40

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

aws-golang-http-get-post/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build:
44
dep ensure -v
55
env GOOS=linux go build -ldflags="-s -w" -o bin/getBin getFolder/getExample.go
66
env GOOS=linux go build -ldflags="-s -w" -o bin/postBin postFolder/postExample.go
7+
env GOOS=linux go build -ldflags="-s -w" -o bin/getQueryBin getFolder/getQueryExample.go
78

89
clean:
910
rm -rf ./bin ./vendor Gopkg.lock

aws-golang-http-get-post/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Serverless boilerplate code for golang with GET and POST example
44
This example is using AWS Request and Response Proxy Model, provided by AWS itself.
55
If you want to test any changes don't forget to run `make` inside the service directory.
66

7-
There are two endpoint provided:
7+
There are three endpoint provided:
88
1. GET endpoint with name parameter (/get/{name})
9-
2. POST endpoint with name in the body (/post - with JSON body {"name":$name}
9+
2. GET endpoint with query string parameter (getQ?name=$name)
10+
3. POST endpoint with name in the body (/post - with JSON body {"name":$name}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/aws/aws-lambda-go/events"
7+
"github.com/aws/aws-lambda-go/lambda"
8+
)
9+
10+
// Handler function Using AWS Lambda Proxy Request
11+
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
12+
13+
//Get the path parameter that was sent
14+
name := request.QueryStringParameters["name"]
15+
16+
//Generate message that want to be sent as body
17+
message := fmt.Sprintf(" { \"Message\" : \"Hello %s \" } ", name)
18+
19+
//Returning response with AWS Lambda Proxy Response
20+
return events.APIGatewayProxyResponse{Body: message, StatusCode: 200}, nil
21+
}
22+
23+
func main() {
24+
lambda.Start(Handler)
25+
}

aws-golang-http-get-post/serverless.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ functions:
6363
parameter:
6464
paths:
6565
name: true
66+
getquery:
67+
handler: bin/getQueryBin
68+
events:
69+
- http:
70+
path: getQ
71+
method: get
72+
request:
73+
parameters:
74+
querystrings:
75+
name: true
6676
post:
6777
handler: bin/postBin
6878
events:

0 commit comments

Comments
 (0)