Giter VIP home page Giter VIP logo

go-req's Introduction

Go HTTP Client

This repository contains a Go package that provides a flexible and easy-to-use HTTP client for making HTTP requests. The client allows you to set headers, configure request modifiers, and send requests to a given URL.

The idea is to provide you with chainable functions that make it easy to call HTTP requests, especially if you are familiar with the Fetch API in the JavaScript world, which I personally love for its simplicity.

Features

  • Set headers: You can easily set custom headers for your HTTP requests.
  • Set the base URL: Create a base URL for your client instance so you can shorten the API URL string and reduce the repetition of the URL pattern.
  • Request modifiers: You can add request modifiers, such as modifying the request body or performing custom operations on the request before sending it.
  • Flexible configuration: The client allows you to configure the base URL and customize the underlying HTTP client.

Installation

To use this package, you need to have Go installed on your machine. Then, you can install the package using the following command:

go get github.com/LightningDev/go-req

Usage

Here's an example of how to use the Client struct and its methods:

package main

import (
	"log"
	"net/http"

	client "github.com/LightningDev/go-req"
)

func main() {
	get()
	post()
}

// GET request
func get() {
	client := client.New("https://animechan.xyz")
	resp, err := client.Fetch("GET", "/api/random")

	if err != nil {
		log.Fatal(err)
	}

	log.Println("Response: " + string(resp) + "\n")
}

// POST request
func post() {
	client := client.New("https://api-ssl.bitly.com")
	data := `{ "long_url": "https://github.com/LightningDev/go-req", "domain": "bit.ly" }`

	header := &http.Header{}
	header.Set("Authorization", "Bearer {YOUR_BITLY_TOKEN}")
	header.Set("Content-Type", "application/json")

	resp, err := client.
		SetHeadersFromObject(header).
		SetBody(data).
		Fetch("POST", "/v4/shorten")

	if err != nil {
		log.Fatal(err)
	}

	log.Println("Response: " + string(resp) + "\n")
}

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

go-req's People

Contributors

lightningdev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.