httpbatch

package module
v0.0.0-...-47d8fff Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 7 Imported by: 1

README

http-batch

Go Report Card

A simple http batch extension for the logjam load testing tool

The aim of this module is to provide the ability to send a batch of HTTP requests concurrently and in parallel, providing responses in a readable format with information that we care about. In addition to this, the pacakage tries to make constructing the array of requests as easy and readable as possible.

Features

  • Pure Go library
  • Simple and Readable API
  • Less than 200 lines of code

How it works

Behind the scenes it uses an array of easily readable Request data structs that eventually maps out to http.NewRequests(). Then it sets a concurrency limit based on the size of the batch of requests and sends them concurrently and in parallel. Once the requests are finished it orders and formats the received responses. This may make a bit more sense after reading the code and following the below example:

Simplest Working Example

package main

import (
    "fmt"

    "github.com/logjamdev/http-batch"
)

func main() {
    var requests = []Request{
    	{
	    Method:  "GET",
	    URL:     "https://httpbin.org/get",
	    Headers: nil,
            Body:    nil,
	},
	{
	    Method: "POST",
	    URL:    "https://httpbin.org/post",
	    Headers: map[string][]string{
	        "Accept": {"application/json"},
	    },
	    Body: map[string]string{
		"name":  "Test API Guy",
		"email": "testapiguy@email.com",
	    },
	},
    }

    batch, err := Batch(requests)
    if err != nil {
        fmt.Println(err)
    }
    responses := batch.Send()
    fmt.Println(responses)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Batch

func Batch(requests []Request) (*batch, error)

Batch is a constructor function for the batch struct.

Types

type Request

type Request struct {
	Method  string
	URL     string
	Headers map[string][]string
	Body    map[string]string
}

Request holds information to create a new http request.

Jump to

Keyboard shortcuts

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