response

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

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

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 3 Imported by: 0

README

jsonapi-response

GoDoc

Response for APIs that conform http://jsonapi.org specification.

Documentation

Overview

Package response provides Response type for use with APIs that conform http://jsonapi.org specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error is JSON:API response error.

func NewError

func NewError() Error

NewError returns a new Error.

func (Error) WithStatus

func (e Error) WithStatus(status int) Error

WithStatus returns error with the HTTP status code applicable to the problem.

func (Error) WithTitle

func (e Error) WithTitle(title string) Error

WithTitle returns error with a short, human-readable summary of the problem.

type Response

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

Response is JSON:API response.

func BadRequest

func BadRequest() Response

BadRequest returns generic 4xx response.

func Created

func Created(data interface{}) Response

Created returns 201 Created response..

func Forbidden

func Forbidden() Response

Forbidden returns 403 Forbidden response.

func InternalServerError

func InternalServerError() Response

InternalServerError returns 500 Internal Server Error response.

func New

func New() Response

New returns a new Response, which status code is 200 by default.

func NotFound

func NotFound() Response

NotFound returns 404 Not Found response.

func OK

func OK(data interface{}) Response

OK returns 200 OK response.

func Unauthorized

func Unauthorized() Response

Unauthorized returns 401 Unauthorized response.

func (Response) MustWrite

func (r Response) MustWrite(w http.ResponseWriter)

MustWrite writes the response to w or panics if any error occurs.

func (Response) WithData

func (r Response) WithData(data interface{}) Response

WithData returns response with the specific data.

func (Response) WithError

func (r Response) WithError(err Error) Response

WithError returns response with the specific error.

func (Response) WithStatus

func (r Response) WithStatus(code int) Response

WithStatus returns response with the specific status code.

func (Response) Write

func (r Response) Write(w http.ResponseWriter) error

Write writes the response to w.

Jump to

Keyboard shortcuts

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