rest

package
v0.13.10 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RestPathPrefix = ""

RestPathPrefix is a prefix you can use in front of all goradd rest paths, like a directory path, to indicate that this is a goradd REST path. You can normally leave this blank if you are only implementing a REST API. If you are implementing different APIs, specify the path here to indicate that the user is making a REST call.

Functions

func HandleRequest

func HandleRequest(w http.ResponseWriter, r *http.Request) bool

func RegisterPath

func RegisterPath(path string, handler RestPathHandler)

RegisterPath associates the given URL path with the given creation function. Call this from an init() function. Afterwards, whenever a user navigates to the given path, the result of the query will be presented to the user.

Types

type HttpError

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

HttpError represents an error response to a http request.

func (*HttpError) Send

func (e *HttpError) Send(errCode int)

Send will cause the page to error with the given http error code.

func (*HttpError) SetResponseHeader

func (e *HttpError) SetResponseHeader(key, value string)

SetResponseHeader sets a key-value in the header response.

type RestManager

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

The RestManager is a singleton global that manages the registration and deployment of rest paths. It acts like a URL router, returning the RestPathHandler that corresponds to a particular URL path. init() functions should be created for each path that associates a function to create a rest path, with the URL that corresponds to the path.

func GetRestManager

func GetRestManager() *RestManager

GetRestManager returns the current page manager.

type RestManagerI

type RestManagerI interface {
	RegisterPath(path string, creationFunction RestPathHandler)
}

type RestPathHandler

type RestPathHandler func(ctx context.Context, buf *bytes.Buffer, headers map[string]string) error

RestPathHandler is a function that handles a REST request.

It should return the headers that describe the response. For example, if returning JSON, it should set the "Content-Type" to "application/json".

Jump to

Keyboard shortcuts

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