requests

package module
v0.0.0-...-9da99ae Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: MIT Imports: 5 Imported by: 0

README

Requests

The http Request Wrapper for Golang.

Licence

MIT

Author

sdn0303

Install

go get github.com/sdn0303/requests

Usage

Sample GET

package main

import (
    "fmt"

    "github.com/sdn0303/requests"
)

func main() {
	endpoint := "https://google.com"

	// Create New requests client and set timeout 15sec 
	req := requests.New(requests.TimeOut(15))
	resp, _ := req.Get(endpoint, map[string]string{})

	fmt.Println(string(resp.Body))
	fmt.Println(resp.Status)
}

Contribution

  1. Fork (https://github.com/sdn0303/requests/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

Documentation

Overview

Copyright (c) 2020 Soichi David Nakahashi Released under the MIT license. see https://github.com/sdn0303/requests/blob/master/LICENSE

Copyright (c) 2020 Soichi David Nakahashi Released under the MIT license. see https://github.com/sdn0303/requests/blob/master/LICENSE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Requests)

Option functional options

func MaxRetry

func MaxRetry(limit uint64) Option

MaxRetry set retry limit on requests client

func TimeOut

func TimeOut(limit int) Option

TimeOut set time out limit on requests client

type Requests

type Requests struct {
	Headers    map[string]string
	HttpClient *http.Client
	RetryLimit uint64
}

Requests struct of http client

func New

func New(options ...Option) *Requests

New initialize http client and set options

func (*Requests) Delete

func (requests *Requests) Delete(endpoint string, query map[string]string) (*ResponseData, error)

Delete

func (*Requests) Get

func (requests *Requests) Get(endpoint string, query map[string]string) (*ResponseData, error)

Get

func (*Requests) Patch

func (requests *Requests) Patch(endpoint string, query map[string]string, data []byte) (*ResponseData, error)

Patch

func (*Requests) Post

func (requests *Requests) Post(endpoint string, query map[string]string, data []byte) (*ResponseData, error)

Post

func (*Requests) Put

func (requests *Requests) Put(endpoint string, query map[string]string, data []byte) (*ResponseData, error)

Put

type ResponseData

type ResponseData struct {
	Headers    http.Header
	Body       []byte
	Status     string
	StatusCode int
}

ResponseData struct of response data

Jump to

Keyboard shortcuts

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