rest

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeController

func ServeController[T any](path string, router mojito.Router, ctrl Controller[T]) error

ServeController will register a REST controller on a given router with the given path and apply a special middleware to provide injection features (not dependency injection!)

Types

type Controller

type Controller[T any] interface {

	// Create is called when the POST endpoint is called with a valid object as its body
	Create(req *mojito.Request, res *mojito.Response, newObj *T) (*T, error)

	// Delete is called when the DELETE endpoint is called with a unique resource identifier
	Delete(req *mojito.Request, res *mojito.Response, obj *T) (*T, error)

	// Get is called when the rest GET endpoint is called with a unique resource identifier
	Get(req *mojito.Request, res *mojito.Response, obj *T) (*T, error)

	// List is called when the rest GET endpoint is called without a unique resource identifier
	// Optionally, Go-Mojito will parse filtering options like pagination into the filter object.
	List(req *mojito.Request, res *mojito.Response, filter ListFilter) ([]T, error)

	// Update is called when the PUT endpoint is called with a valid object as its body and with
	// a valid unique resource identifier
	Update(req *mojito.Request, res *mojito.Response, obj *T, updatedObj *T) (*T, error)

	// ResolveIdentifier defines how the rest controller can retrieve a unique value, based on the
	// resource identifier
	ResolveIdentifier(req *mojito.Request, identifier string) (*T, error)
}

Controller defines the interface of a valid REST controller

type ListFilter

type ListFilter struct {
}

ListFilter defines possible filters for the rest list endpoint

Jump to

Keyboard shortcuts

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