Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Curl = RequestTemplate{
RequestStr: `curl -X {{.Method}} {{.URL}}{{if .Headers}} \{{else if .Body}} \{{end}}
{{range $name, $value := .Headers}} -H {{$name}} {{range $internal := $value}}{{$internal}}{{end}} \{{end}}
{{if .Body}}
-d '{{.Body}}'
{{end}}`,
}
Curl : template
View Source
var Go = RequestTemplate{
ClientStr: `package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
// Client : my client
type Client struct { }
{{.Code}}
`,
FunctionStr: `func (c Client) {{.Label}}() {
{{.Code}}
}
`,
RequestStr: `req, err := http.NewRequest("{{.Method}}", "{{.URL}}", {{if .Body}}strings.NewReader(` + "`" + `{{.Body}}` + "`" + `){{else}}nil{{end}})
{{range $name, $value := .Headers}}req.Header.Set("{{$name}}", "{{range $internal := $value}}{{$internal}}{{end}}")
{{end}}
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(body))`,
}
Go : template
View Source
var Javascript = RequestTemplate{
ClientStr: `
class Client {
{{- .Code -}}
}
`,
FunctionStr: `{{if not .Client}}function {{end}}{{.Label}}() {
{{.Code}}
}`,
RequestStr: `fetch('{{.URL}}', {
method: '{{.Method}}',
{{- if .Headers}}
headers: {
{{range $name, $value := .Headers}} '{{$name}}': '{{range $internal := $value}}{{$internal}}{{end}}',
{{end}} },
{{- end}}
{{- if .Body}}
body: JSON.stringify({{.Body}}),
{{- end}}
})
.then((res) => res.json().then((data) => ({ status: res.status, data })))
.then(({ status, data }) => console.log(status, data))`,
}
Javascript : template
View Source
var Node = RequestTemplate{
ClientStr: `const fetch = require('node-fetch')
class Client {
{{- .Code -}}
}
`,
FunctionStr: `{{if not .Client}}function {{end}}{{.Label}}() {
{{.Code}}
}`,
RequestStr: `fetch('{{.URL}}', {
method: '{{.Method}}',
{{- if .Headers}}
headers: {
{{range $name, $value := .Headers}} '{{$name}}': '{{range $internal := $value}}{{$internal}}{{end}}',
{{end}} },
{{- end}}
{{- if .Body}}
body: JSON.stringify({{.Body}}),
{{- end}}
})
.then((res) => res.json().then((data) => ({ status: res.status, data })))
.then(({ status, data }) => console.log(status, data))`,
}
Node : template
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.