summaryrefslogtreecommitdiff
path: root/system/api/server.go
blob: c6d29bf9012b82b8e2d2c8ffaba3ceedda8254e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package api

import (
	"bytes"
	"fmt"
	"log"
	"net/http"
)

// Run adds Handlers to default http listener for API
func Run() {
	http.HandleFunc("/api/types", CORS(Record(typesHandler)))

	http.HandleFunc("/api/contents", CORS(Record(contentsHandler)))

	http.HandleFunc("/api/content", CORS(Record(contentHandler)))

	http.HandleFunc("/api/content/external", CORS(Record(externalContentHandler)))
}

// ContentAll retrives all items from the HTTP API within the provided namespace
func ContentAll(namespace string) [][]byte {
	endpoint := "http://0.0.0.0:8080/api/contents?type="
	buf := []byte{}
	r := bytes.NewReader(buf)
	req, err := http.NewRequest(http.MethodGet, endpoint+namespace, r)
	if err != nil {
		log.Println("Error creating request for reference from:", namespace)
		return nil
	}

	c := http.Client{}
	res, err := c.Do(req)

	fmt.Println(res, string(buf))

	ret := [][]byte{}
	return append(ret, buf)
}