summaryrefslogtreecommitdiff
path: root/system/api/server.go
blob: 7254a7bfd212f86da12c99d1b2d64f430a13ae80 (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
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) [][]bytes {
	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:", contentType)
		return nil
	}

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

	fmt.Println(res, string(buf))

	return []byte{buf}
}