Skip to content

Commit

Permalink
Docs: More comments on ExampleBuilder_BodyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Sep 25, 2023
1 parent 0bb0b98 commit 6490858
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions builder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func ExampleBuilder_BodyJSON() {
"Hello", 42, []bool{true, false},
}

// A request using the default serializer
// Build a request using the default JSON serializer
req, err := requests.
New().
BodyJSON(&data).
Expand All @@ -667,6 +667,7 @@ func ExampleBuilder_BodyJSON() {
panic(err)
}

// JSON is packed in with no whitespace
io.Copy(os.Stdout, req.Body)
fmt.Println()

Expand All @@ -676,7 +677,7 @@ func ExampleBuilder_BodyJSON() {
requests.JSONSerializer = defaultSerializer
}()

// Serialize with indented JSON
// Have the default JSON serializer indent with two spaces
requests.JSONSerializer = func(v any) ([]byte, error) {
return json.MarshalIndent(v, "", " ")
}
Expand All @@ -688,7 +689,9 @@ func ExampleBuilder_BodyJSON() {
panic(err)
}

// Now the request body is indented
io.Copy(os.Stdout, req.Body)
fmt.Println()

// Output:
// {"a":"Hello","b":42,"c":[true,false]}
Expand Down

0 comments on commit 6490858

Please sign in to comment.