Coder Social home page Coder Social logo

gorequests's Introduction

GoRequests

A golang library Based on standard lib, the name comes from that Python requests.

Design

It's request in a session, you can do:

  • get
  • post
    • form data
    • json
  • put
  • delete
  • options

Usage

package main

import (
	"fmt"
	"github.com/GuoBoy/goRequests"
	"log"
)

func main() {
	session := goRequests.NewSession()
	accessApi := "http://localhost:8080"
	headers := map[string]string{
		"User-Agent": "Mozilla Chrome 111.1.1",
	}
	body := fmt.Sprintf(`{"username": "admin", "password": "admin"}`)
	accessResp, err := session.PostJson(accessApi, headers, body)
	if err != nil {
		log.Fatal("获取access_token失败", err)
	}
	// 获取access响应结构体
	type accessRespModel struct {
		AccessToken  string `json:"access_token"`
		RefreshToken string `json:"refresh_token"`
	}
	var result accessRespModel
	err = accessResp.Json(&result)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(result)
}

Get more

TODO

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.