GithubHelp home page GithubHelp logo

request's Introduction

Request

request is an intuitive and flexible HTTP client written in Go. Inspired by the simplicity of the project req, this library aims to provide a higher level of abstraction for handling HTTP requests and responses. With a wide range of customization options, it makes sending HTTP requests and handling responses simpler and more efficient.

Features

  • Support for all basic HTTP methods: GET, POST, PATCH, PUT, DELETE.
  • Built-in JSON and form data support for request bodies.
  • Cookie jar support for easier cookie management.
  • Dynamic and easy setting of query parameters and headers.
  • Integrated basic authentication.
  • Customizable timeouts and transport settings.
  • Context support for cancellable and timeout requests.
  • String, byte array, and io.Reader support for request bodies.
  • Helper methods for response handling: read as string, read all, convert to JSON, save to file.

Example Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/faceair/request"
)

func main() {
	client := request.New()

	client.SetBaseURL("https://api.github.com").
		SetBaseHeaders(request.Headers{
			"Accept": "application/vnd.github.v3+json",
		})

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	resp, err := client.Get(ctx, "/users/octocat")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("Response:", resp.String())
}

This will send a GET request to https://api.github.com/users/octocat with the Accept header set as application/vnd.github.v3+json and a timeout of 5 seconds.

License

MIT.

request's People

Contributors

faceair 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.