@dhruvdutt/

Appbase.io - Go - index

Go

Insert any JSON object

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.30373560660327126","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJInN0cmluZ3MiCgkibmV0L2h0dHAiCgkiaW8vaW91dGlsIgoJImVuY29kaW5nL2pzb24iCgkiYnl0ZXMiCgkiZm10IgopCgpmdW5jIG1haW4oKSB7CgoJdXJsIDo9ICJodHRwczovL3NjYWxyLmFwaS5hcHBiYXNlLmlvL2hvdXNpbmctZGVtby9saXN0aW5nL0gxIgoKCXBheWxvYWQgOj0gc3RyaW5ncy5OZXdSZWFkZXIoYHsKICAgICJuYW1lIjogIlRoZSBXaGl0ZSBIb3VzZSIsCiAgICAicm9vbV90eXBlIjogIlByaXZhdGUgcm9vbSIsCiAgICAicHJvcGVydHlfdHlwZSI6ICJUb3duaG91c2UiLAogICAgInByaWNlIjogMTI0LAogICAgImhhc19hdmFpbGFiaWxpdHkiOiAidHJ1ZSIsCiAgICAiYWNjb21tb2RhdGVzIjogMiwKICAgICJiZWRyb29tcyI6IDEsCiAgICAiYmF0aHJvb21zIjogMS41LAogICAgImJlZHMiOiAxLAogICAgImJlZF90eXBlIjogIlJlYWwgQmVkIiwKICAgICJob3N0X2ltYWdlIjogImh0dHBzOi8vYTIubXVzY2FjaGUuY29tL2FjL3BpY3R1cmVzLzdjMjhhMTU1LTNlYjgtNDM4ZC04ZjUxLTQyNmIxOTFhYjc5NS5qcGc/aW50ZXJwb2xhdGlvbj1sYW5jem9zLW5vbmUmY3JvcD13Onc7KiwqJmNyb3A9aDpoOyosKiZyZXNpemU9NTA6KiZvdXRwdXQtZm9ybWF0PWpwZyZvdXRwdXQtcXVhbGl0eT03MCIsCiAgICAiaG9zdF9uYW1lIjogIkFseXNvbiIsCiAgICAiaW1hZ2UiOiAiaHR0cHM6Ly9hMC5tdXNjYWN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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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main

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

func main() {

	url := "https://scalr.api.appbase.io/housing-demo/listing/H1"

	payload := strings.NewReader(`{
    "name": "The White House",
    "room_type": "Private room",
    "property_type": "Townhouse",
    "price": 124,
    "has_availability": "true",
    "accommodates": 2,
    "bedrooms": 1,
    "bathrooms": 1.5,
    "beds": 1,
    "bed_type": "Real Bed",
    "host_image": "https://a2.muscache.com/ac/pictures/7c28a155-3eb8-438d-8f51-426b191ab795.jpg?interpolation=lanczos-none&crop=w:w;*,*&crop=h:h;*,*&resize=50:*&output-format=jpg&output-quality=70",
    "host_name": "Alyson",
    "image": "https://a0.muscache.com/im/pictures/68837752/96cae4d1_original.jpg?aki_policy=medium",
    "listing_url": "https://www.airbnb.com/rooms/5364119",
    "location": {
        "lat": 47.53540733743967,
        "lon": -122.27983057017123
    },
    "date_from": 20170426,
    "date_to": 20170421
  }`)

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

	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)

  // 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()))

}