fetch

package module
v0.0.0-...-c4cacf7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: MIT Imports: 7 Imported by: 0

README

Fetch for Go!

Inspired by the lightweight node-fetch package in Node.js, fetch is meant as a light utility for fetching and parsing web pages, especially for JSON based REST API's.

Its two primary functions are GetJson and PostJson which accept and return Json data using https://github.com/bitly/go-simplejson

Example usage:

package main

import (
	"github.com/kklash/fetch"
	"fmt"
)

func main() {
	data, err := fetch.GetJson("http://ipinfo.io/json")
	if err != nil {
		panic(err)
	}

	ip, _ := data.Get("ip").String()

	city, _ := data.Get("city").String()

	fmt.Printf("IP: %s\nLocation: %s\n", ip, city)
// => IP: 93.115.86.8
//    Location: Bucharest
}

Documentation

Overview

Fetch provides a super simple API for get and post-requesting REST API's, plus converting to/from JSON

Fetch provides a super simple API for get and post-requesting REST API's, plus converting to/from JSON

Index

Constants

View Source
const JSON_CONTENT_TYPE = "application/json"

Variables

Functions

func Get

func Get(url string) ([]byte, error)

func GetJson

func GetJson(url string) (*json.Json, error)

func Post

func Post(url string, postData []byte) ([]byte, error)

func PostJson

func PostJson(url string, postData *json.Json) (*json.Json, error)

func UseProxy

func UseProxy(proxyURL string) error

Sets fetch up to use a custom proxy. For example, to use the tor browser's socks5 proxy: fetch.UseProxy("socks5://127.0.0.1:9150")

Types

This section is empty.

Jump to

Keyboard shortcuts

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