Documentation
¶
Overview ¶
Package httpfile parses the common subset of the `.http` request file format used by VS Code REST Client, JetBrains HTTP Client, kulala.nvim and httpyac, plus apic's own `# @capture` / `# @assert` comment directives.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var KnownDirectives = map[string]string{
"name": "request name used on the command line",
"description": "one-line description shown by list/describe",
"capture": "store a response value: `# @capture name = selector`",
"assert": "assert on the response: `# @assert selector op value`",
"auth": "authentication: `# @auth bearer|basic|aws|oauth2|exec|none ...`",
"step": "Gherkin phrase that runs this request: `# @step a user named {name} exists`",
"no-redirect": "do not follow redirects",
"no-session": "do not persist captures from this request",
"timeout": "per-request timeout, e.g. `10s`",
"note": "free text, ignored (REST Client compatibility)",
"prompt": "REST Client prompt, ignored (pass with --var instead)",
}
KnownDirectives are the `# @key` directives apic understands. Others are reported as warnings by validate but otherwise ignored.
Functions ¶
func Parse ¶
func Parse(path, content string) (*File, []Diagnostic)
Parse parses .http content. path is used only for diagnostics and IDs.
Types ¶
type Capture ¶
Capture declares that a value selected from the response should be stored under Name for later requests: `# @capture token = body.$.access_token`.
type Diagnostic ¶
type Diagnostic struct {
Path string `json:"path"`
Line int `json:"line"`
Severity string `json:"severity"` // "error" or "warning"
Message string `json:"message"`
}
Diagnostic is a non-fatal problem found while parsing.
func (Diagnostic) String ¶
func (d Diagnostic) String() string
type Request ¶
type Request struct {
File *File
Index int // 1-based position within the file
Name string // from `# @name`, may be empty
Title string // free text after `###`
Description string // from `# @description`, else Title
Directives []Directive
Captures []Capture
Asserts []Assert
Method string
URL string // raw template
HTTPVersion string
Headers []Header
Body string // raw template, empty when none
BodyFile string // set when the body is `< ./file`
BodyFileTemplated bool // `<@ ./file`: substitute {{vars}} inside the file too
Line int // line number of the request line
}
Request is one request block within a file.