Documentation ¶
Overview ¶
Package api implements a JSON-API for interacting with a affix node
Index ¶
- Constants
- Variables
- func GetBodyCSVHandler(inst *lib.Instance) http.HandlerFunc
- func GetHandler(inst *lib.Instance, routePrefix string) http.HandlerFunc
- func HTTPSRedirect(addr string)
- func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- func NewServerRoutes(s Server) *mux.Router
- func SaveByUploadHandler(inst *lib.Instance, routePrefix string) http.HandlerFunc
- func StartServer(c *config.API, s *http.Server) error
- func TokenHandler(inst *lib.Instance) http.HandlerFunc
- func UnpackHandler(routePrefix string) http.HandlerFunc
- func WebuiHandler(w http.ResponseWriter, r *http.Request)
- type Server
- func (s *Server) HandleIPFSPath(w http.ResponseWriter, r *http.Request)
- func (s *Server) HomeHandler(w http.ResponseWriter, r *http.Request)
- func (s Server) Middleware(handler http.HandlerFunc) http.HandlerFunc
- func (s Server) NoLogMiddleware(handler http.HandlerFunc) http.HandlerFunc
- func (s Server) Serve(ctx context.Context) (err error)
Constants ¶
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" )
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" )
const ( // AEToken is the token provider endpoint AEToken qhttp.APIEndpoint = "/oauth/token" )
const DefaultWebappPort = 2505
DefaultWebappPort is the default port the web app will listen on
Variables ¶
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 ¶
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 ¶
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 ¶
Server wraps a affix p2p node, providing traditional access via http Create one with New, start it up with Serve
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