Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rbretecher/go-postman-collection
Go module to work with Postman Collections
https://github.com/rbretecher/go-postman-collection
Last synced: about 2 months ago
JSON representation
Go module to work with Postman Collections
- Host: GitHub
- URL: https://github.com/rbretecher/go-postman-collection
- Owner: rbretecher
- License: mit
- Created: 2019-11-16T12:13:32.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-17T11:59:02.000Z (7 months ago)
- Last Synced: 2024-07-31T20:53:20.122Z (5 months ago)
- Language: Go
- Size: 85.9 KB
- Stars: 76
- Watchers: 2
- Forks: 19
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-postman-collection - Go module to work with [Postman Collections](https://learning.getpostman.com/docs/postman/collections/creating-collections/) (compatible with Insomnia). (Third-party APIs / Utility/Miscellaneous)
- awesome-go-extra - go-postman-collection - 11-16T12:13:32Z|2022-07-20T14:59:41Z| (Third-party APIs / Fail injection)
README
# go-postman-collection
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/rbretecher/go-postman-collection)
[![Build Status](https://travis-ci.org/rbretecher/go-postman-collection.svg?branch=master)](https://travis-ci.org/rbretecher/go-postman-collection)
[![Report](https://goreportcard.com/badge/github.com/rbretecher/go-postman-collection)](https://goreportcard.com/report/github.com/rbretecher/go-postman-collection)
[![Code coverage](https://codecov.io/gh/rbretecher/go-postman-collection/branch/master/graph/badge.svg)](https://codecov.io/gh/rbretecher/go-postman-collection)Go module to work with Postman Collections.
This module aims to provide a simple way to work with Postman collections. Using this module, you can create collections, update them and export them into the Postman Collection format v2 (compatible with Insomnia)
Postman Collections are a group of saved requests you can organize into folders. For more information about Postman Collections, you can visit the [official documentation](https://www.getpostman.com/collection).
## Examples
### Collections
#### Read a Postman Collection
```go
package mainimport (
"os"postman "github.com/rbretecher/go-postman-collection"
)func main() {
file, err := os.Open("postman_collection.json")
defer file.Close()if err != nil {
panic(err)
}c, err := postman.ParseCollection(file)
_ = c
}
```#### Create and save a Postman Collection
```go
package mainimport (
"os"postman "github.com/rbretecher/go-postman-collection"
)func main() {
c := postman.CreateCollection("My collection", "My awesome collection")c.AddItemGroup("A folder").AddItem(&postman.Item{
Name: "This is a request",
Request: Request{
URL: &URL{
Raw: "http://www.google.fr",
},
Method: postman.Get,
},
})file, err := os.Create("postman_collection.json")
defer file.Close()if err != nil {
panic(err)
}err = c.Write(file)
if err != nil {
panic(err)
}
}
```### Items
`Items` are the basic unit for a Postman collection, it can either be a request (`Item`) or a folder (`ItemGroup`).
```go
// Create a simple item.
item := postman.CreateItem(postman.Item{
Name: "A basic request",
Request: Request{
URL: &URL{
Raw: "http://www.google.fr",
},
Method: postman.Get,
}
})// Create a simple folder.
folder := postman.CreateItemGroup(postman.ItemGroup{
Name: "A folder",
})// Add the item to the folder
folder.AddItem(item)
```### Request
Part of the `Item`, a `Request` represents an HTTP request.
```go
// Basic request
req := Request{
URL: &URL{
Raw: "http://www.google.fr",
},
Method: postman.Get,
}// Complex request
req := postman.Request{
URL: &postman.URL{
Raw: "http://www.google.fr",
},
Method: postman.Post,
Body: &postman.Body{
Mode: "raw",
Raw: "{\"key\": \"value\"}",
},
}
```### Auth
`Auth` can be added to a `Request` or an `ItemGroup`.
```go
// Create basic auth with username and password
auth := postman.CreateAuth(postman.Basic, postman.CreateAuthParam("username", "password"))
```### Variable
`Variable` can be added to `Collection`, `Item`, `ItemGroup` and `URL`.
```go
v := postman.CreateVariable("env", "prod")
```## Current support
For now, it does not offer support all objects. Feel free to submit a pull request if you want to add support for one of those objects.
| Object | v2.0.0 | v2.1.0 |
| ------------------ | ------ | ------ |
| Collection | Yes | Yes |
| ItemGroup (Folder) | Yes | Yes |
| Item | Yes | Yes |
| Request | Yes | Yes |
| Response | Yes | Yes |
| Event | Yes | Yes |
| Variable | Yes | Yes |
| Auth | Yes | Yes |