api

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActivityPubAcceptHeaders = []Offer{
	AppActivityJSON,
	AppActivityLDJSON,
}

ActivityPubAcceptHeaders represents the Accept headers mentioned here: https://www.w3.org/TR/activitypub/#retrieving-objects

View Source
var HTMLAcceptHeaders = []Offer{
	TextHTML,
}

HTMLAcceptHeaders is a slice of offers that just contains text/html types.

View Source
var JSONAcceptHeaders = []Offer{
	AppJSON,
}

JSONAcceptHeaders is a slice of offers that just contains application/json types.

Functions

func NegotiateAccept added in v0.2.0

func NegotiateAccept(c *gin.Context, offers ...Offer) (string, error)

NegotiateAccept takes the *gin.Context from an incoming request, and a slice of Offers, and performs content negotiation for the given request with the given content-type offers. It will return a string representation of the first suitable content-type, or an error if something goes wrong or a suitable content-type cannot be matched.

For example, if the request in the *gin.Context has Accept headers of value [application/json, text/html], and the provided offers are of value [application/json, application/xml], then the returned string will be 'application/json', which indicates the content-type that should be returned.

If the length of offers is 0, then an error will be returned, so this function should only be called in places where format negotiation is actually needed.

If there are no Accept headers in the request, then the first offer will be returned, under the assumption that it's better to serve *something* than error out completely.

Callers can use the offer slices exported in this package as shortcuts for often-used Accept types.

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation#server-driven_content_negotiation

Types

type ClientModule

type ClientModule interface {
	Route(s router.Router) error
}

ClientModule represents a chunk of code (usually contained in a single package) that adds a set of functionalities and/or side effects to a router, by mapping routes and/or middlewares onto it--in other words, a REST API ;) A ClientAPIMpdule with routes corresponds roughly to one main path of the gotosocial REST api, for example /api/v1/accounts/ or /oauth/

type FederationModule

type FederationModule interface {
	Route(s router.Router) error
}

FederationModule represents a chunk of code (usually contained in a single package) that adds a set of functionalities and/or side effects to a router, by mapping routes and/or middlewares onto it--in other words, a REST API ;) Unlike ClientAPIModule, federation API module is not intended to be interacted with by clients directly -- it is primarily a server-to-server interface.

type Offer added in v0.2.0

type Offer string

Offer represents an offered mime-type.

const (
	AppJSON           Offer = `application/json`                                                     // AppJSON is the mime type for 'application/json'.
	AppActivityJSON   Offer = `application/activity+json`                                            // AppActivityJSON is the mime type for 'application/activity+json'.
	AppActivityLDJSON Offer = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"` // AppActivityLDJSON is the mime type for 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
	TextHTML          Offer = `text/html`                                                            // TextHTML is the mime type for 'text/html'.
)

Jump to

Keyboard shortcuts

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