Skip to content

Commit 0b1841d

Browse files
author
Jason Kao
committed
added header docs on readme & inline
1 parent bd91370 commit 0b1841d

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ Low-level GraphQL client for Go.
99
* Use variables and upload files
1010
* Simple error handling
1111

12+
## Installation
13+
Make sure you have a working Go environment. To install graphql, simply run:
14+
15+
```
16+
$ go get github.com/machinebox/graphql
17+
```
18+
19+
## Usage
20+
1221
```go
1322
import "context"
1423

@@ -29,6 +38,9 @@ req := graphql.NewRequest(`
2938
// set any variables
3039
req.Var("key", "value")
3140

41+
// set header fields
42+
req.Header.Set("Cache-Control", "no-cache")
43+
3244
// define a Context for the request
3345
ctx := context.Background()
3446

graphql.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,29 @@ type graphResponse struct {
178178

179179
// Request is a GraphQL request.
180180
type Request struct {
181-
q string
182-
vars map[string]interface{}
183-
files []file
181+
q string
182+
vars map[string]interface{}
183+
files []file
184+
185+
// Header mirrors the Header of a http.Request. It contains
186+
// the request header fields either received
187+
// by the server or to be sent by the client.
188+
//
189+
// If a server received a request with header lines,
190+
//
191+
// Host: example.com
192+
// accept-encoding: gzip, deflate
193+
// Accept-Language: en-us
194+
// fOO: Bar
195+
// foo: two
196+
//
197+
// then
198+
//
199+
// Header = map[string][]string{
200+
// "Accept-Encoding": {"gzip, deflate"},
201+
// "Accept-Language": {"en-us"},
202+
// "Foo": {"Bar", "two"},
203+
// }
184204
Header Header
185205
}
186206

0 commit comments

Comments
 (0)