Skip to content

Sending Requests

Martin Kim Dung-Pham edited this page Aug 28, 2017 · 8 revisions

Using the Sputnik Binary

Using the binary, you can send requests directly from the command line. In order to get the binary:

go install github.com/q231950/sputnik

Simple example for sending a post request:

sputnik requests post -p '{"query": {"recordType":"City"}, "resultsLimit": 1}' -o query -c iCloud.com.elbedev.bishcommunity

More elaborate example

sputnik requests post -p '{"query": {"recordType":"City", "filterBy": [{"comparator": "EQUALS", "fieldName": "name", "fieldValue": {"value":"Tokyo"}}]}, "resultsLimit": 10}' -o query -c iCloud.com.elbedev.bishcommunity 

Example with a json file

sputnik requests post -j ./cmd/fixtures/sample_payload.json -o query -c iCloud.com.elbedev.bishcommunity

Required parameters for the post/get commands:

-o query marks the operation. As an example, for creating a record, the operation would be modify

-c iCloud.com... marks the container to access

Specification of the query:

-p '{"query": {"recordType":"City"}, "resultsLimit": 1}' is the payload of the request

or

-j './path/to/file.json' would add a payload using a path to a file

For more information, checkout the help:

sputnik help requests post


Using Sputnik as a package

Post Requests

import (
 keymanager "github.com/q231950/sputnik/keymanager"
 requests "github.com/q231950/sputnik/requesthandling"
)

keyManager := keymanager.New()

config := requesthandling.RequestConfig{Version: "1", ContainerID: "iCloud.com...", Database: "public"}
requestManager := requesthandling.New(config, &keyManager)

request, error := requestManager.PostRequest("modify", json)
client := &http.Client{}
response, error := client.Do(request)

Get Requests

...
request, error := requestManager.GetRequest("modify", json)
...
⌂ 换网址