pantopoda

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2019 License: MIT Imports: 11 Imported by: 0

README

Pantopoda

Pantopoda is a collection of tools related to HTTP request/response

Installation

go get -u github.com/Kamva/pantopoda

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorType added in v0.2.0

type ErrorType string

ErrorType is a string subtype used inside ValidationError type which determines the type of validation error. There are two type of validation errors; BadRequest, that returned when the request payload did not match with request data structure. And RuleViolation, that returned when any of specified rules in validation tag violated in incoming request payload.

const BadRequest ErrorType = "bad_request"

BadRequest that returned when the request payload did not match with request data structure

const RuleViolation ErrorType = "validation_failed"

RuleViolation that returned when any of specified rules in validation tags violated in incoming request payload.

type JSONArray added in v0.2.1

type JSONArray []JSONBody

JSONArray represents the body with an array of json objects.

func (JSONArray) ToJSON added in v0.2.1

func (body JSONArray) ToJSON() []byte

ToJSON converts the JSONArray to json bytes

type JSONBody added in v0.2.1

type JSONBody map[string]interface{}

JSONBody represents the json object body.

func (JSONBody) ToJSON added in v0.2.1

func (body JSONBody) ToJSON() []byte

ToJSON converts the JSONBody to json bytes

type Pantopoda added in v0.2.0

type Pantopoda struct {
}

Pantopoda is a HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services.

func NewPantopoda added in v0.2.0

func NewPantopoda() *Pantopoda

NewPantopoda generate new instance of pantopoda client

func (*Pantopoda) Delete added in v0.2.0

func (c *Pantopoda) Delete(endpoint string, request Request) (Response, error)

Delete sends a DELETE request to `endpoint` with given given data.

func (*Pantopoda) Get added in v0.2.0

func (c *Pantopoda) Get(endpoint string, request Request) (Response, error)

Get sends a GET request to `endpoint` with given data.

func (*Pantopoda) Patch added in v0.2.0

func (c *Pantopoda) Patch(endpoint string, request Request) (Response, error)

Patch sends a PATCH request to `endpoint` with given given data.

func (*Pantopoda) Post added in v0.2.0

func (c *Pantopoda) Post(endpoint string, request Request) (Response, error)

Post sends a POST request to `endpoint` with given data.

func (*Pantopoda) Put added in v0.2.0

func (c *Pantopoda) Put(endpoint string, request Request) (Response, error)

Put sends a PUT request to `endpoint` with given given data.

func (*Pantopoda) Request added in v0.2.0

func (c *Pantopoda) Request(method string, endpoint string, request Request) (Response, error)

Request sends a `method` request to the `endpoint` with given request data.

type QueryParams added in v0.2.0

type QueryParams map[string][]string

QueryParams represent url query params.

func (QueryParams) Empty added in v0.2.0

func (q QueryParams) Empty() bool

Empty checks if query param is empty.

func (QueryParams) ToString added in v0.2.0

func (q QueryParams) ToString() string

ToString converts QueryParams map to its string representation.

type Request added in v0.2.0

type Request struct {
	// Payload represent json body of HTTP call.
	Payload RequestBody

	// Query represent query params of HTTP call endpoint.
	Query QueryParams

	// Headers represent headers of HTTP call.
	Headers RequestHeaders
}

Request represent all data such as payload, query params, and header of a JSON HTTP request call.

func (*Request) HasBody added in v0.3.0

func (r *Request) HasBody() bool

HasBody checks that request has payload

type RequestBody added in v0.2.0

type RequestBody interface {
	ToJSON() []byte
}

RequestBody represents the json body in an HTTP request body.

type RequestData

type RequestData interface {
	nautilus.Taggable

	// Validate runs request data validation and returns validation error if
	Validate() ValidationError
}

RequestData is an interface for incoming request payload

type RequestHeaders added in v0.2.0

type RequestHeaders map[string]string

RequestHeaders represents the key-value pairs in an HTTP header.

type Response added in v0.2.0

type Response struct {
	StatusCode code.StatusCode
	Headers    http.Header
	// contains filtered or unexported fields
}

Response represents HTTP call response body.

func (Response) ToString added in v0.2.0

func (r Response) ToString() string

ToString convert the response body to its string value.

func (Response) Unmarshal added in v0.2.0

func (r Response) Unmarshal(v interface{}) error

Unmarshal parses the JSON-encoded response and stores the result in the value pointed to by v.

type ResponseError added in v0.3.1

type ResponseError struct {
	Status  string
	Payload []byte
}

ResponseError is an error implementation for client and server errors in API calls.

func (ResponseError) Error added in v0.3.1

func (e ResponseError) Error() string

type ValidationError added in v0.2.0

type ValidationError struct {
	// ErrorBag contains any validation errors on request fields.
	ErrorBag shark.ErrorBag

	// ErrorType is a string determine type of the validation error.
	ErrorType ErrorType
}

ValidationError is an error type containing validation error bag and error type determine type of validation error.

func Validate added in v0.2.0

func Validate(r RequestData) ValidationError

Validate runs request data validation and returns validation error

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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