Skip to content

Instantly share code, notes, and snippets.

@jonathaningram
Created May 11, 2016 05:57
Show Gist options
  • Save jonathaningram/d63103349f4433742ff26564531aa3e6 to your computer and use it in GitHub Desktop.
Save jonathaningram/d63103349f4433742ff26564531aa3e6 to your computer and use it in GitHub Desktop.
You can create an App Engine POST task with a JSON body as well as a form-encoded one. You just need to set the Payload and Content-Type.
package main
import (
"encoding/json"
"net/http"
"google.golang.org/appengine/taskqueue"
)
// NewJSONPostTask creates a Task that will POST to a path with the given body
// encoded as JSON.
func NewJSONPostTask(path string, body interface{}) (*taskqueue.Task, error) {
h := make(http.Header)
h.Set("Content-Type", "application/json")
b, err := json.Marshal(body)
if err != nil {
return nil, err
}
return &taskqueue.Task{
Path: path,
Payload: b,
Header: h,
Method: "POST",
}, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment