Git Product home page Git Product logo

lra's Introduction

Build Status Go Report Card GoDoc license cover.run

lra - a lowlevel REST api client

This package handles REST API calls and allows for using http and socks proxies as well as self signed certificates. It also allows the specification of headers to be sent with every request.

I wrote this after copying code for various tools connecting to different REST APIs. It consolidates the low level functionality of establishing/configuring a connction and doing the HTTP requests.

License

BSD 3-clause license

Contributions

Contributions / Pull requests are welcome.

Documentation

https://godoc.org/github.com/joernott/lra

Usage

Create connection

A new connection can pe created using the NewConnection function

	hl := make(lra.HeaderList)
	hl["Content-Type"] = "application/json"
	connection,err := lra.NewConnection(
		true,                             // use SSL
		"elasticsearch.example.com",      // server name
		9200,                             // port
		"",                               // no additional base endpoint
		"admin",                          // user name
		"1234",                           // password
		false,                            // we use a certificate generatewd by the elasticsearch CA
		"https://proxy.example.com:3128", // We use a proxy
		false,                            // it is not a socks5 proxy
		hl                                // We want to pass those headers
	)

Get a result

Getting a raw []byte:

  statusRaw,err := connection.Get("/_cluster/health")

Getting parsed JSON:

  statusJson,err := connection.GetJSON("/_cluster/health")

Other API functions

Currently the standard CRUD operations DELETE, GET, PUT, POST are implemented. In addition, CONNECT, HEAD, OPTIONS, PATCH and TRACE are implemented but so far, I didn't need them. So they have not been battle-tested.

For every type, there is a function returning the raw []byte data and a function with the suffix JSON which attempts to parse the data into a json map[string]interface{}.

lra's People

Contributors

joernott avatar

Watchers

James Cloos avatar  avatar  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.