Popularity
1.0
Growing
Activity
7.2
Declining
7
1
1

Programming language: Go
Tags: Networking     HTTP Clients    

go-http-client alternatives and similar packages

Based on the "HTTP Clients" category

Do you think we are missing an alternative of go-http-client or a related project?

Add another 'HTTP Clients' Package

README

go-http-client

An enhanced http client for Golang

Documentation on GoDoc 🔗

This package provides you a http client package for your http requests. You can send requests quicly with this package. If you want to contribute this package, please fork and create a pull request.

Installation

$ go get github.com/bozd4g/go-http-client/

Usage

import (
    "fmt"
    "github.com/bozd4g/go-http-client/client"
    "github.com/mitchellh/mapstructure"
)

type Todo struct {
    Id        int
    UserId    int
    Title     string
    Completed bool
}

func main() {
    client := client.HttpClient{BaseUrl: "http://jsonplaceholder.typicode.com"}
    response := client.PostWith("/posts", Todo{
        Id:        1,
        UserId:    1,
        Title:     "Lorem ipsum dolor sit amet",
        Completed: true,
    })

    if response.IsSuccess {
        var todo Todo
        mapstructure.Decode(response.Data, &todo)
        fmt.Println(todo.Title) // Lorem ipsum dolor sit amet

    } else {
        fmt.Println(response.Message)
    }
}

Functions

All functions return a type called ServiceResponse as below.

type ServiceResponse struct {
    IsSuccess bool
    StatusCode int
    StatusText string
    Message string
    Data interface {}
}

You can call these functions from your application.

Function Has Params
Get(endpoint string) -
GetWith(endpoint string, params interface {}) Yes
Post(endpoint string) -
PostWith(endpoint string, params interface {}) Yes
Put(endpoint string) -
PutWith(endpoint string, params interface{}) Yes
Delete(endpoint string) -
DeleteWith(endpoint string, params interface{}) Yes

License

Copyright (c) 2020 Furkan Bozdag

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


*Note that all licence references and agreements mentioned in the go-http-client README section above are relevant to that project's source code only.