package
0.0.0-20200416044943-d22e7c36ff52
Repository: https://github.com/albertwidi/go-project-example.git
Documentation: pkg.go.dev

# README

HTTP Request Builder

This package is an HTTP request builder for go

Get Request

import "github.com/albertwidi/internal/pkg/http/request"

func main() {
    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Get("https://google.com").
        Compile()
    if err != nil {
        // do something with error
    }

Get Request With Query

import "github.com/albertwidi/internal/pkg/http/request"

func main() {
    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Get("https://google.com").
        Query("key", "value").
        Compile()
    if err != nil {
        // do something with error
    }

Query receive variadic parameters with type string

Post Request

import "github.com/albertwidi/internal/pkg/http/request"

func main() {
    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Post("https://google.com").
        Compile()
    if err != nil {
        // do something with error
    }

Post Form

import "github.com/albertwidi/internal/pkg/http/request"

func main() {
    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Post("https://google.com").
        PostForm("key", "value")
        Compile()
    if err != nil {
        // do something with error
    }

PostForm receive variadic parameters with type string

Request Body

JSON

import "github.com/albertwidi/internal/pkg/http/request"

func main() {
    s := struct {
        Asd string `json:"asd"`
        Jkl string `json:"jkl"`
    }{}

    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Post("https://google.com").
        BodyJSON(s).
        Compile()
    if err != nil {
        // do something with error
    }

Raw/io.Reader

func main() {
    s := struct {
        Asd string `json:"asd"`
        Jkl string `json:"jkl"`
    }{}

    // req  is a *http.Request 
    req, err := request.New(context.Background()).
        Post("https://google.com").
        BodyJSON(s).
        Compile()
    if err != nil {
        // do something with error
    }

Version Selection Header

To be added

# Functions

Header function.
New http request wrapper.

# Variables

RoutingContext is a key name for version selection routing.

# Structs

Request wrap the http request.