postman

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

# krakend-postman

A simple Postman collection generator from KrakenD config

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleCollection

func HandleCollection(c Collection) func(http.ResponseWriter, *http.Request)

HandleCollection returns a simple http.HandleFunc exposing the POSTMAN collection description

Example
cfg := config.ServiceConfig{
	Port: 8080,
	Name: "sample",
	Endpoints: []*config.EndpointConfig{
		{
			Endpoint: "/foo",
			Method:   "GET",
		},
	},
}

parsedConfig, _ := Parse(cfg)
ts := httptest.NewServer(http.HandlerFunc(HandleCollection(parsedConfig)))
defer ts.Close()

res, err := http.Get(ts.URL)
if err != nil {
	fmt.Println(err.Error())
}

c := Collection{}
if err := json.NewDecoder(res.Body).Decode(&c); err != nil {
	fmt.Println(err.Error())
}
res.Body.Close()

fmt.Println(c.Info.Name)
fmt.Println(c.Info.Schema)
fmt.Println(len(c.Item))
fmt.Printf("%+v\n", c.Item[0].Name)
fmt.Printf("%+v\n", c.Item[0].Item)
fmt.Printf("%+v\n", c.Item[0].Request.URL.Raw)
fmt.Println(len(c.Variables))
fmt.Printf("%+v\n", c.Variables[0].Key)
fmt.Printf("%+v\n", c.Variables[0].Value)
fmt.Printf("%+v\n", c.Variables[0].Type)
fmt.Printf("%+v\n", c.Variables[1].Key)
fmt.Printf("%+v\n", c.Variables[1].Value)
fmt.Printf("%+v\n", c.Variables[1].Type)
Output:

sample
https://schema.getpostman.com/json/collection/v2.1.0/collection.json
1
/foo
[]
{{SCHEMA}}://{{HOST}}/foo
2
HOST
localhost:8080
string
SCHEMA
http
string

Types

type Body

type Body struct {
	Mode string `json:"mode,omitempty"`
	Raw  string `json:"raw,omitempty"`
}

type Collection

type Collection struct {
	Variables []Variable `json:"variables"`
	Info      Info       `json:"info"`
	Item      ItemList   `json:"item"`
}

func Parse

func Parse(cfg config.ServiceConfig) (Collection, error)

Parse converts the received service config into a simple POSTMAN collection description @see https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html

type Header []struct {
	Key         string `json:"key"`
	Value       string `json:"value"`
	Description string `json:"description,omitempty"`
}

type Info

type Info struct {
	Name        string   `json:"name"`
	PostmanID   string   `json:"_postman_id"`
	Description string   `json:"description,omitempty"`
	Schema      string   `json:"schema"`
	Version     *Version `json:"version,omitempty"`
}

type Item

type Item struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Request     *Request `json:"request,omitempty"`
	Item        ItemList `json:"item,omitempty"`
}

type ItemList

type ItemList []*Item

type Request

type Request struct {
	URL         URL      `json:"url"`
	Method      string   `json:"method"`
	Header      []Header `json:"header,omitempty"`
	Body        *Body    `json:"body,omitempty"`
	Description string   `json:"description,omitempty"`
}

type URL

type URL struct {
	Raw      string   `json:"raw"`
	Protocol string   `json:"protocol"`
	Host     []string `json:"host"`
	Path     []string `json:"path"`
}

type Variable

type Variable struct {
	ID    string `json:"id"`
	Key   string `json:"key"`
	Value string `json:"value"`
	Type  string `json:"type"`
}

type Version

type Version struct {
	Major uint64 `json:"major"`
	Minor uint64 `json:"minor"`
	Patch uint64 `json:"patch"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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