loading
open in
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"strings"
	"net/http"
	"io/ioutil"
	"encoding/json"
	"bytes"
	"fmt"
)

func main() {

	url := "https://scalr.api.appbase.io/newstreamingapp/listing/_bulk"
	
	payload := strings.NewReader(`{"index":{"_id":"X1"}}
{"department_id":1,"department_name":"Books","department_name_analyzed":"Books","id":"X1","name":"A Fake Book on Network Routing","price":1032}
{"index":{"_id":"X2"}}
{"department_id":2,"department_name":"Books","department_name_analyzed":"Books","id":"X2","name":"A Fake Book on Computer Science","price":4125}
{"index":{"_id":"X3"}}
{"department_id":3,"department_name":"Books","department_name_analyzed":"Books","id":"X3","name":"A Fake Book on Reactive Programming","price":3846}
`)

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Basic bWVxUmY4S0pDOjY1Y2MxNjFhLTIyYWQtNDBjNS1hYWFmLTVjMDgyZDVkY2ZkYQ==")
	req.Header.Add("Content-Type", "application/x-ndjson")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

  // prettify
	var prettyJSON bytes.Buffer
	error := json.Indent(&prettyJSON, body, "", "\t")
	if error != nil {
		fmt.Println("JSON parse error: ", error)
		return
	}

	fmt.Println(string(prettyJSON.Bytes()))

}