httpfile

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

func ParseFile

func ParseFile(path string) (*File, []Diagnostic, error)

ParseFile reads and parses a .http file from disk.

Types

type Assert

type Assert struct {
	Expr string
	Line int
}

Assert is a raw assertion expression: `# @assert status == 200`.

type Capture

type Capture struct {
	Name     string
	Selector string
	Line     int
}

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 Directive

type Directive struct {
	Key   string
	Value string
	Line  int
}

Directive is a `# @key value` comment placed before a request line.

type File

type File struct {
	Path     string
	Vars     []Var
	Requests []*Request
}

File is a parsed .http file.

type Header struct {
	Name  string
	Value string
}

Header is a raw, un-templated request header.

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.

func (*Request) Directive

func (r *Request) Directive(key string) (string, bool)

Directive returns the value of the first directive with the given key.

func (*Request) ID

func (r *Request) ID() string

ID returns the stable identifier used on the command line: the request's name when it has one, else `<file>#<index>`.

func (*Request) Steps

func (r *Request) Steps() []string

Steps returns every `# @step` phrase declared on the request.

type Var

type Var struct {
	Name  string
	Value string
	Line  int
}

Var is a file-level variable declared as `@name = value`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL