The POST method

Now we know how the GET method works with and without path parameters. The next step will be to pass a JSON payload to a Lambda function through the API Gateway. The code is self-explanatory. It converts the request input to a movie structure, adds it to the list of movies, and returns the new list of movies in a JSON format: 

package mainimport (  "encoding/json"  "github.com/aws/aws-lambda-go/events"  "github.com/aws/aws-lambda-go/lambda")type Movie struct {  ID int `json:"id"`  Name string `json:"name"`}var movies = []Movie{  Movie{    ID: 1,    Name: "Avengers",  },  ...}func insert(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {  var movie Movie  err := json.Unmarshal([]byte(req.Body), &movie) if err != nil ...

Get Hands-On Serverless Applications with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.