api

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Overview

Package api implements a JSON-API for interacting with a qri node

Index

Constants

View Source
const (
	// DefaultTemplateHash is the hash of the default render template
	DefaultTemplateHash = "/ipfs/QmeqeRTf2Cvkqdx4xUdWi1nJB2TgCyxmemsL3H4f1eTBaw"
	// TemplateUpdateAddress is the URI for the template update
	TemplateUpdateAddress = "/ipns/defaulttmpl.qri.io"
)
View Source
const (

	// AEHome is the / endpoint
	AEHome = lib.APIEndpoint("/")
	// AEHealth is the service health check endpoint
	AEHealth = lib.APIEndpoint("/health")
	// AEIPFS is the IPFS endpoint
	AEIPFS = lib.APIEndpoint("/qfs/ipfs/{path:.*}")
	// AEWebUI serves the remote WebUI
	AEWebUI = lib.APIEndpoint("/webui")

	// AEGetCSVFullRef is the route used to get a body as a csv, that can also handle a specific hash
	AEGetCSVFullRef = lib.APIEndpoint("/ds/get/{username}/{name}/at/{fs}/{hash}/body.csv")
	// AEGetCSVShortRef is the route used to get a body as a csv
	AEGetCSVShortRef = lib.APIEndpoint("/ds/get/{username}/{name}/body.csv")
	// AEUnpack unpacks a zip file and sends it back
	AEUnpack = lib.APIEndpoint("/ds/unpack")
)
View Source
const DefaultWebappPort = 2505

DefaultWebappPort is the default port the web app will listen on

Variables

View Source
var (

	// APIVersion is the version string that is written in API responses
	APIVersion = version.Version
)

Functions

func DatasetRefFromCtx added in v0.1.2

func DatasetRefFromCtx(ctx context.Context) reporef.DatasetRef

DatasetRefFromCtx extracts a Dataset reference from a given context if one is set, returning nil otherwise

func DatasetRefFromReq added in v0.1.2

func DatasetRefFromReq(r *http.Request) (dsref.Ref, error)

DatasetRefFromReq examines the path element of a request URL to

func GetBodyCSVHandler added in v0.10.0

func GetBodyCSVHandler(inst *lib.Instance) http.HandlerFunc

GetBodyCSVHandler is a handler for returning the body as a csv file Examples: curl http://localhost:2503/ds/get/b5/world_bank_population/body.csv

func GetHandler added in v0.10.0

func GetHandler(inst *lib.Instance, routePrefix string) http.HandlerFunc

GetHandler is a dataset single endpoint

func HTTPSRedirect

func HTTPSRedirect(addr string)

HTTPSRedirect listens over TCP on addr, redirecting HTTP requests to https

func HealthCheckHandler added in v0.5.1

func HealthCheckHandler(w http.ResponseWriter, r *http.Request)

HealthCheckHandler is a basic ok response for load balancers & co returns the version of qri this node is running, pulled from the lib package

func NewServerRoutes

func NewServerRoutes(s Server) *mux.Router

NewServerRoutes returns a Muxer that has all API routes

func StartServer

func StartServer(c *config.API, s *http.Server) error

StartServer interprets info from config to start an API server

func UnmarshalParams added in v0.10.0

func UnmarshalParams(r *http.Request, p interface{}) error

UnmarshalParams deserializes a lib req params stuct pointer from an HTTP request. Only used for handlers that do not use lib.NewHTTPMethodRequest.

func UnpackHandler added in v0.10.0

func UnpackHandler(routePrefix string) http.HandlerFunc

UnpackHandler unpacks a zip file and sends it back as json

func WebuiHandler added in v0.9.12

func WebuiHandler(w http.ResponseWriter, r *http.Request)

WebuiHandler returns the webui html

Types

type QriCtxKey added in v0.1.2

type QriCtxKey string

QriCtxKey defines a distinct type for keys for context values should always use custom types to avoid collisions. see comment on context.WithValue for more info

const DatasetRefCtxKey QriCtxKey = "datasetRef"

DatasetRefCtxKey is the key for adding a dataset reference to a context.Context

type RequestUnmarshaller added in v0.10.0

type RequestUnmarshaller interface {
	UnmarshalFromRequest(r *http.Request) error
}

RequestUnmarshaller is an interface for deserializing from an HTTP request

type Server

type Server struct {
	*lib.Instance
	Mux *mux.Router
	// contains filtered or unexported fields
}

Server wraps a qri p2p node, providing traditional access via http Create one with New, start it up with Serve

func New

func New(inst *lib.Instance) Server

New creates a new qri server from a p2p node & configuration

func (*Server) HandleIPFSPath

func (s *Server) HandleIPFSPath(w http.ResponseWriter, r *http.Request)

HandleIPFSPath responds to IPFS Hash requests with raw data

func (*Server) HomeHandler added in v0.10.0

func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request)

HomeHandler responds with a health check on the empty path, 404 for everything else

func (Server) Middleware added in v0.10.0

func (s Server) Middleware(handler http.HandlerFunc) http.HandlerFunc

Middleware handles request logging

func (Server) NoLogMiddleware added in v0.10.0

func (s Server) NoLogMiddleware(handler http.HandlerFunc) http.HandlerFunc

NoLogMiddleware runs middleware without logging the request

func (Server) Serve

func (s Server) Serve(ctx context.Context) (err error)

Serve starts the server. It will block while the server is running

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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