parser

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package parser provides functionality for parsing .http and .rest files into structured HTTP request models with support for variables, multipart forms, and embedded scripts.

Index

Constants

View Source
const RequestDelimiter = "###"

RequestDelimiter is used to separate multiple requests in one file

Variables

This section is empty.

Functions

func FindDuplicateNames added in v0.2.10

func FindDuplicateNames(requests []*models.HttpRequest) map[string][]DuplicateName

FindDuplicateNames returns a map of duplicate names to their occurrences

func ParseFile

func ParseFile(filePath string, defaultHeaders map[string]string) ([]*models.HttpRequest, error)

ParseFile parses an HTTP request file

func ParseFileAt

func ParseFileAt(filePath string, index int, defaultHeaders map[string]string) (*models.HttpRequest, error)

ParseFileAt parses a specific request from a file (by index)

func ParseFileByName

func ParseFileByName(filePath string, name string, defaultHeaders map[string]string) (*models.HttpRequest, error)

ParseFileByName parses a named request from a file

Types

type DuplicateName added in v0.2.10

type DuplicateName struct {
	Name   string
	Method string
	URL    string
	Index  int // 0-based index of the request
}

DuplicateName holds information about a request with a duplicate name

type HttpRequestParser

type HttpRequestParser struct {
	// contains filtered or unexported fields
}

HttpRequestParser parses HTTP request files (.http, .rest)

func NewHttpRequestParser

func NewHttpRequestParser(content string, defaultHeaders map[string]string, baseDir string) *HttpRequestParser

NewHttpRequestParser creates a new parser

func (*HttpRequestParser) ParseAll

func (p *HttpRequestParser) ParseAll() ([]*models.HttpRequest, error)

ParseAll parses all requests from the content (backward compatible - ignores warnings)

func (*HttpRequestParser) ParseAllWithWarnings added in v0.2.4

func (p *HttpRequestParser) ParseAllWithWarnings() *ParseResult

ParseAllWithWarnings parses all requests and returns warnings for invalid blocks

func (*HttpRequestParser) ParseRequest

func (p *HttpRequestParser) ParseRequest(rawText string) (*models.HttpRequest, error)

ParseRequest parses a single HTTP request from text

type ParseResult added in v0.2.4

type ParseResult struct {
	Requests []*models.HttpRequest
	Warnings []ParseWarning
}

ParseResult contains the parsed requests and any warnings

func ParseFileWithWarnings added in v0.2.4

func ParseFileWithWarnings(filePath string, defaultHeaders map[string]string) (*ParseResult, error)

ParseFileWithWarnings parses an HTTP request file and returns warnings

type ParseState

type ParseState int

ParseState represents the current state of parsing

const (
	ParseStateURL ParseState = iota
	ParseStateHeader
	ParseStateBody
	ParseStatePostScript
)

type ParseWarning added in v0.2.4

type ParseWarning struct {
	BlockIndex int    // Index of the block (0-based)
	Line       int    // Line number within the block (0-based)
	Message    string // Warning message
}

ParseWarning represents a warning generated during parsing

Jump to

Keyboard shortcuts

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