Documentation
¶
Overview ¶
Package postman provides import and export functionality for Postman Collection v2.1 format.
This package enables bidirectional conversion between Postman collections/environments and LazyCurl's internal formats. It supports:
- Importing Postman Collection v2.1 files
- Importing Postman Environment files
- Exporting LazyCurl collections to Postman format
- Exporting LazyCurl environments to Postman format
- Auto-detecting file types (collection vs environment)
Import Example ¶
result, err := postman.ImportCollection("/path/to/collection.json")
if err != nil {
log.Fatal(err)
}
if result.HasWarnings() {
for _, w := range result.Summary.Warnings {
log.Printf("Warning: %s", w)
}
}
// Use result.Collection
Export Example ¶
err := postman.ExportCollection(collection, "/path/to/export.json")
if err != nil {
log.Fatal(err)
}
Supported Features ¶
The following Postman features are fully supported:
- Collections with nested folders (unlimited depth)
- All HTTP methods (GET, POST, PUT, PATCH, DELETE, etc.)
- Request headers with enabled/disabled state
- Query parameters
- Body types: raw (JSON, text, XML), urlencoded, formdata
- Authentication: Bearer, Basic, API Key
- Environment variables with secret/enabled flags
Unsupported Features ¶
The following Postman features generate warnings but don't prevent import:
- Pre-request scripts (stored but not executed)
- Test scripts (stored but not executed)
- OAuth 2.0 authentication (warning generated)
- GraphQL body type (imported as raw)
- File uploads (path preserved only)
Index ¶
- func ExportCollection(collection *api.CollectionFile, filePath string) error
- func ExportCollectionToBytes(collection *api.CollectionFile) ([]byte, error)
- func ExportEnvironment(env *api.EnvironmentFile, filePath string) error
- func ExportEnvironmentToBytes(env *api.EnvironmentFile) ([]byte, error)
- type Auth
- type AuthKeyValue
- type Body
- type BodyOptions
- type Collection
- type Environment
- type EnvironmentValue
- type Event
- type FileBody
- type FileType
- type FormDataParam
- type GraphQLBody
- type Header
- type ImportResult
- type ImportSummary
- type Info
- type Item
- type QueryParam
- type RawOptions
- type Request
- type Script
- type URL
- type URLEncodedParam
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExportCollection ¶
func ExportCollection(collection *api.CollectionFile, filePath string) error
ExportCollection exports a LazyCurl collection to Postman Collection v2.1 format.
func ExportCollectionToBytes ¶
func ExportCollectionToBytes(collection *api.CollectionFile) ([]byte, error)
ExportCollectionToBytes exports a LazyCurl collection to Postman JSON bytes.
func ExportEnvironment ¶
func ExportEnvironment(env *api.EnvironmentFile, filePath string) error
ExportEnvironment exports a LazyCurl environment to Postman environment format.
func ExportEnvironmentToBytes ¶
func ExportEnvironmentToBytes(env *api.EnvironmentFile) ([]byte, error)
ExportEnvironmentToBytes exports a LazyCurl environment to Postman JSON bytes.
Types ¶
type Auth ¶
type Auth struct {
Type string `json:"type"`
Bearer []AuthKeyValue `json:"bearer,omitempty"`
Basic []AuthKeyValue `json:"basic,omitempty"`
APIKey []AuthKeyValue `json:"apikey,omitempty"`
}
Auth contains authentication configuration.
type AuthKeyValue ¶
type AuthKeyValue struct {
Key string `json:"key"`
Value string `json:"value"`
Type string `json:"type,omitempty"`
}
AuthKeyValue represents a key-value pair in auth configuration.
type Body ¶
type Body struct {
Mode string `json:"mode"`
Raw string `json:"raw,omitempty"`
URLEncoded []URLEncodedParam `json:"urlencoded,omitempty"`
FormData []FormDataParam `json:"formdata,omitempty"`
Options *BodyOptions `json:"options,omitempty"`
File *FileBody `json:"file,omitempty"`
GraphQL *GraphQLBody `json:"graphql,omitempty"`
}
Body contains request body definition.
type BodyOptions ¶
type BodyOptions struct {
Raw *RawOptions `json:"raw,omitempty"`
}
BodyOptions contains body format options.
type Collection ¶
type Collection struct {
Info Info `json:"info"`
Item []Item `json:"item"`
Variable []Variable `json:"variable,omitempty"`
Auth *Auth `json:"auth,omitempty"`
}
Collection represents the root structure of a Postman Collection v2.1 file.
type Environment ¶
type Environment struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Values []EnvironmentValue `json:"values"`
PostmanVariableScope string `json:"_postman_variable_scope,omitempty"`
}
Environment represents a Postman environment export file.
type EnvironmentValue ¶
type EnvironmentValue struct {
Key string `json:"key"`
Value string `json:"value"`
Type string `json:"type,omitempty"` // default or secret
Enabled bool `json:"enabled"`
}
EnvironmentValue represents an environment variable.
type Event ¶
type Event struct {
Listen string `json:"listen"` // prerequest or test
Script Script `json:"script"`
}
Event represents a pre-request or test script.
type FileBody ¶
type FileBody struct {
Src string `json:"src,omitempty"`
Content string `json:"content,omitempty"`
}
FileBody represents a file body.
type FileType ¶
type FileType int
FileType represents the detected type of a Postman file.
func DetectFileType ¶
DetectFileType determines if a file is a Postman collection or environment.
func DetectFileTypeFromBytes ¶
DetectFileTypeFromBytes determines the file type from raw JSON bytes.
type FormDataParam ¶
type FormDataParam struct {
Key string `json:"key"`
Value string `json:"value,omitempty"`
Type string `json:"type"` // text or file
Src string `json:"src,omitempty"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
FormDataParam represents a form-data parameter.
type GraphQLBody ¶
type GraphQLBody struct {
Query string `json:"query,omitempty"`
Variables string `json:"variables,omitempty"`
}
GraphQLBody represents a GraphQL body.
type Header ¶
type Header struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
Header represents a request header.
type ImportResult ¶
type ImportResult struct {
Collection *api.CollectionFile // Non-nil if collection import succeeded
Environment *api.EnvironmentFile // Non-nil if environment import succeeded
Summary ImportSummary
Error error
}
ImportResult represents the result of an import operation.
func ImportCollection ¶
func ImportCollection(filePath string) (*ImportResult, error)
ImportCollection imports a Postman Collection v2.1 file and converts it to LazyCurl format.
func ImportCollectionFromBytes ¶
func ImportCollectionFromBytes(data []byte) (*ImportResult, error)
ImportCollectionFromBytes imports a Postman Collection from raw JSON bytes.
func ImportEnvironment ¶
func ImportEnvironment(filePath string) (*ImportResult, error)
ImportEnvironment imports a Postman Environment file and converts it to LazyCurl format.
func ImportEnvironmentFromBytes ¶
func ImportEnvironmentFromBytes(data []byte) (*ImportResult, error)
ImportEnvironmentFromBytes imports a Postman Environment from raw JSON bytes.
func (*ImportResult) FormatSummary ¶
func (r *ImportResult) FormatSummary() string
FormatSummary returns a human-readable summary string.
func (*ImportResult) HasWarnings ¶
func (r *ImportResult) HasWarnings() bool
HasWarnings returns true if there are warnings in the summary.
func (*ImportResult) Success ¶
func (r *ImportResult) Success() bool
Success returns true if the import succeeded without errors.
type ImportSummary ¶
type ImportSummary struct {
CollectionName string
RequestsCount int
FoldersCount int
EnvironmentName string
VariablesCount int
Warnings []string
Errors []string
}
ImportSummary contains statistics and messages from an import operation.
func (*ImportSummary) AddErrorf ¶
func (s *ImportSummary) AddErrorf(format string, args ...interface{})
AddErrorf adds an error message to the summary.
func (*ImportSummary) AddWarningf ¶
func (s *ImportSummary) AddWarningf(format string, args ...interface{})
AddWarningf adds a warning message to the summary.
func (*ImportSummary) FormatCollectionSummary ¶
func (s *ImportSummary) FormatCollectionSummary() string
FormatCollectionSummary returns a formatted string for collection import.
func (*ImportSummary) FormatEnvironmentSummary ¶
func (s *ImportSummary) FormatEnvironmentSummary() string
FormatEnvironmentSummary returns a formatted string for environment import.
type Info ¶
type Info struct {
PostmanID string `json:"_postman_id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schema string `json:"schema"`
}
Info contains collection metadata.
type Item ¶
type Item struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Request *Request `json:"request,omitempty"`
Item []Item `json:"item,omitempty"`
Event []Event `json:"event,omitempty"`
}
Item represents either a request or a folder (item group). If Request is nil, it's a folder containing nested Items.
type QueryParam ¶
type QueryParam struct {
Key string `json:"key"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
QueryParam represents a URL query parameter.
type RawOptions ¶
type RawOptions struct {
Language string `json:"language"` // json, xml, text, javascript, html
}
RawOptions specifies the raw body language.
type Request ¶
type Request struct {
Method string `json:"method"`
Header []Header `json:"header,omitempty"`
Body *Body `json:"body,omitempty"`
URL URL `json:"url"`
Auth *Auth `json:"auth,omitempty"`
Description string `json:"description,omitempty"`
}
Request contains the full request definition.
type Script ¶
type Script struct {
Type string `json:"type"` // text/javascript
Exec []string `json:"exec"` // Script lines
}
Script contains script content.
type URL ¶
type URL struct {
Raw string `json:"raw"`
Protocol string `json:"protocol,omitempty"`
Host []string `json:"host,omitempty"`
Path []string `json:"path,omitempty"`
Query []QueryParam `json:"query,omitempty"`
}
URL contains URL with parsed components.
func (*URL) UnmarshalJSON ¶
UnmarshalJSON handles URL being either a string or an object in Postman collections.