Help us shape the future of Go! Take the 2026 Go Developer Survey

httpie

package module
v0.0.0-...-2fcbd79 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2014 License: MIT Imports: 8 Imported by: 1

README

HTTPie

A small HTTP library for Go. It helps with normal HTTP requests and HTTP streaming.

Example Usage

package main

import (
    "fmt"
    "net/url"
    "github.com/brettbuddin/httpie"
)

func main() {
    // Create a GET endpoint
    endpoint := httpie.Get{&url.URL{
        Scheme: "http",
        Host: "google.com",
        Path: "/robots.txt",
    }}

    // We could alternatively, if we don't need auth, set this to nil
    authorizer := httpie.BasicAuth{"username", "password"}

    // Do the business
    client := httpie.NewClient(authorizer)
    resp, err := client.Request(endpoint)

    if err != nil {
        fmt.Printf("We have an error: %s\n", err)
        return
    }

    fmt.Printf("Our response: %s\n", resp)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NewLine        = Delimeter{'\n'}
	CarriageReturn = Delimeter{'\r'}
	Space          = Delimeter{' '}
	Comma          = Delimeter{','}
)

Functions

This section is empty.

Types

type Authorizer

type Authorizer interface {
	Authorize(*http.Request)
}

Authorizer is implemented to allow delayed attachment of auth data to a request

type BasicAuth

type BasicAuth struct {
	Username, Password string
}

func (BasicAuth) Authorize

func (b BasicAuth) Authorize(req *http.Request)

Authorize applys BasicAuth to a request

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(authorizer Authorizer) *Client

NewClient returns a Client. Provide `nil` if no auth is necessary.

func (*Client) Request

func (c *Client) Request(end Endpoint) (*http.Response, error)

Request makes a request and returns an HTTP response.

type Consumer

type Consumer interface {
	Consume(*bufio.Reader) ([]byte, error)
}

Consumer is implemented to provide a method of breaking up and consuming a stream

type Delete

type Delete struct {
	*url.URL
}

Represents an HTTP DELETE

func (Delete) ApplyTo

func (d Delete) ApplyTo(req *http.Request)

ApplyTo sets the requests Method to DELETE and URL

type Delimeter

type Delimeter struct {
	Delim byte
}

func (Delimeter) Consume

func (d Delimeter) Consume(reader *bufio.Reader) ([]byte, error)

Consume reads up to the next delimeter

type Endpoint

type Endpoint interface {
	ApplyTo(*http.Request)
}

Endpoint is implemented to provide delayed attachment of the URL/Method/Body of a request

type Get

type Get struct {
	*url.URL
}

Represents an HTTP GET

func (Get) ApplyTo

func (g Get) ApplyTo(req *http.Request)

ApplyTo sets the requests Method to GET and URL

type HeaderAuth

type HeaderAuth struct {
	Auth string
}

func (HeaderAuth) Authorize

func (h HeaderAuth) Authorize(req *http.Request)

Authorize applys HeaderAuth to a request

type Post

type Post struct {
	*url.URL
	Body        []byte
	ContentType string
}

Represents an HTTP POST

func (Post) ApplyTo

func (p Post) ApplyTo(req *http.Request)

ApplyTo sets the requests Method to POST, URL and Body

type Put

type Put struct {
	*url.URL
	Body        []byte
	ContentType string
}

Represents an HTTP PUT

func (Put) ApplyTo

func (p Put) ApplyTo(req *http.Request)

ApplyTo sets the requests Method to PUT, URL and Body

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func NewStream

func NewStream(endpoint Endpoint, auth Authorizer, consumer Consumer) *Stream

NewStream returns a Stream

func (*Stream) Connect

func (s *Stream) Connect()

Connect starts the stream

func (*Stream) Data

func (s *Stream) Data() chan []byte

Data returns a channel that chunks of the feed will be communicated upon

func (*Stream) Disconnect

func (s *Stream) Disconnect()

Disconnect forcefully disconnects from the stream

func (*Stream) Errors

func (s *Stream) Errors() chan error

Errors returns a channel that stream errors will be sent over

Jump to

Keyboard shortcuts

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