api

package
v0.0.0-...-5ddb3d2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package api implements a JSON-API for interacting with a affix 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.affix.io"
)
View Source
const (

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

	// AEGetCSVFullRef is the route used to get a body as a csv, that can also handle a specific hash
	AEGetCSVFullRef qhttp.APIEndpoint = "/ds/get/{username}/{name}/at/{fs}/{hash}/body.csv"
	// AEGetCSVShortRef is the route used to get a body as a csv
	AEGetCSVShortRef qhttp.APIEndpoint = "/ds/get/{username}/{name}/body.csv"
	// AEUnpack unpacks a zip file and sends it back
	AEUnpack qhttp.APIEndpoint = "/ds/unpack"
	// AESaveByUpload is the route used to save a dataset using a multipart form file in the request
	AESaveByUpload qhttp.APIEndpoint = "/ds/save/upload"
)
View Source
const (
	// AEToken is the token provider endpoint
	AEToken qhttp.APIEndpoint = "/oauth/token"
)
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 GetBodyCSVHandler

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

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

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

HealthCheckHandler is a basic ok response for load balancers & co returns the version of affix 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 SaveByUploadHandler

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

SaveByUploadHandler saves a dataset by reading the body from a file

func StartServer

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

StartServer interprets info from config to start an API server

func TokenHandler

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

TokenHandler is a handler to authenticate and generate access & refresh tokens

func UnpackHandler

func UnpackHandler(routePrefix string) http.HandlerFunc

UnpackHandler unpacks a zip file and sends it back as json

func WebuiHandler

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

WebuiHandler returns the webui html

Types

type Server

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

Server wraps a affix 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 affix 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

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

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

Middleware handles request logging

func (Server) NoLogMiddleware

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