repl.it
@dhruvdutt/

Appbase.io - Go - range-1

Go

Range query to get all rooms between prices `50` and `100`

fork
loading
Files
  • main.go
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
45
package main

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

func main() {

	url := "https://scalr.api.appbase.io/housing-demo/listing/_search"
	query := strings.NewReader(`{
    "query":{
       "match_all": {}
      }
    }
  `)
	payload, err := ioutil.ReadAll(query)
	if err != nil {
		fmt.Println(err)
	}
	streamBody := ioutil.NopCloser(bytes.NewReader(payload))
	req, _ := http.NewRequest("POST", url, streamBody)

	req.Header.Add("Authorization", "Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==")
	req.Header.Add("Content-Type", "application/json")

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

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)
	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()))

}