restly

package module
v0.0.0-...-213f75e Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2018 License: MIT Imports: 4 Imported by: 3

README

restly - Fast REST client for Go (golang)

Go Report GolangCI Travis codecov License Maintenance GoDoc

This fast REST client combines fasthttp for performance, gjson for JSON searching, and etree for XML searching.

Features:

  • Fully configurable fasthttp.Request struct
  • Automatic encoding REST routes with client libraries (gjson & etree) with support for problem errors RFC7807
  • Automatic encoding for query string parameters
  • About 100 LOC
  • About 10x faster than using net/http
go get github.com/apibillme/restly
req := restly.New()

req.Header.Add("Authorization", "Bearer my_token")

jsonBody := `{"key":"value"}`

xmlBody := `<?xml version="1.0" encoding="UTF-8"?><People><Person name="Jon"/></People></xml>`

res, statusCode, err := restly.GetJSON(req, "https://mockbin.com/request", "?foo=bar")
	
res, statusCode, err := restly.DeleteJSON(req, "https://mockbin.com/request", "?foo=bar")
	
res, statusCode, err := restly.PutJSON(req, "https://mockbin.com/request", jsonBody, "?foo=bar")
	
res, statusCode, err := restly.PostJSON(req, "https://mockbin.com/request", jsonBody, "?foo=bar")
	
res, statusCode, err := restly.PatchJSON(req, "https://mockbin.com/request", jsonBody, "?foo=bar")

res, statusCode, err := restly.GetXML(req, "https://mockbin.com/request", "?foo=bar")
	
res, statusCode, err := restly.DeleteXML(req, "https://mockbin.com/request", "?foo=bar")
	
res, statusCode, err := restly.PutXML(req, "https://mockbin.com/request", xmlBody, "?foo=bar")
	
res, statusCode, err := restly.PostXML(req, "https://mockbin.com/request", xmlBody, "?foo=bar")
	
res, statusCode, err := restly.PatchXML(req, "https://mockbin.com/request", xmlBody, "?foo=bar")

Motivation

I saw the largest problem with Go (Golang) being interacting with JSON & XML with REST clients. At the time the popular REST clients required you to strongly type out each interface you need for the request. This is painful and slow!

I wanted a one-liner request with the ability to dynamically set, find, and extract values from JSON & XML without all the boilerplate of a net/http request. This library delivers you exactly these requirements!

The request body is simply a string and the find/extract interface relies on battle-tested libraries for either JSON (gjson) or XML (etree).

Because this library uses fasthttp rather than net/http it is about 10x faster than competing libraries. It is also only about 100 LOC compared to the massive codebases of competing projects.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteJSON

func DeleteJSON(req *fasthttp.Request, url string, query string) (gjson.Result, int, error)

DeleteJSON - make delete JSON and return searchable JSON and Status Code

func DeleteXML

func DeleteXML(req *fasthttp.Request, url string, query string) (*etree.Document, int, error)

DeleteXML - make delete XML and return searchable XML and Status Code

func GetJSON

func GetJSON(req *fasthttp.Request, url string, query string) (gjson.Result, int, error)

GetJSON - make get JSON and return searchable JSON and Status Code

func GetXML

func GetXML(req *fasthttp.Request, url string, query string) (*etree.Document, int, error)

GetXML - make get XML and return searchable XML and Status Code

func New

func New() *fasthttp.Request

New - create fasthttp request

func PatchJSON

func PatchJSON(req *fasthttp.Request, url string, body string, query string) (gjson.Result, int, error)

PatchJSON - make patch JSON and return searchable JSON and Status Code

func PatchXML

func PatchXML(req *fasthttp.Request, url string, body string, query string) (*etree.Document, int, error)

PatchXML - make patch XML and return searchable XML and Status Code

func PostJSON

func PostJSON(req *fasthttp.Request, url string, body string, query string) (gjson.Result, int, error)

PostJSON - make post JSON and return searchable JSON and Status Code

func PostXML

func PostXML(req *fasthttp.Request, url string, body string, query string) (*etree.Document, int, error)

PostXML - make post XML and return searchable XML and Status Code

func PutJSON

func PutJSON(req *fasthttp.Request, url string, body string, query string) (gjson.Result, int, error)

PutJSON - make put JSON and return searchable JSON and Status Code

func PutXML

func PutXML(req *fasthttp.Request, url string, body string, query string) (*etree.Document, int, error)

PutXML - make put XML and return searchable XML and Status Code

Types

This section is empty.

Jump to

Keyboard shortcuts

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