3 // ========================LICENSE_START=================================
6 // Copyright (C) 2023: Nordix Foundation
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 // ========================LICENSE_END===================================
27 log "github.com/sirupsen/logrus"
29 "github.com/labstack/echo/v4"
30 "oransc.org/nonrtric/capifprov/internal/publishserviceapi"
33 func GetApiRequest(server string) echo.HandlerFunc {
34 return func(c echo.Context) error {
36 aefId := c.FormValue("apfId")
38 return c.Render(http.StatusOK, "getapi.html", map[string]interface{}{
44 //server format: http://localhost:8090
45 url := server + "/published-apis/v1/" + aefId + "/service-apis"
46 log.Infof("[Get API] to %v for aefId: %v", url, aefId)
48 headers := map[string]string{
49 "Content-Type": "text/plain",
51 resp, err := makeRequest("GET", url, headers, nil)
53 log.Errorf("[Get API] %v", fmt.Sprintf("error: %v", err))
54 return c.Render(http.StatusBadRequest, "getapi.html", map[string]interface{}{
55 "response": fmt.Sprintf("error: %v", err),
60 log.Infof("[Get API] Response from service: %+v error: %v\n", string(resp), err)
62 var resAPIs []publishserviceapi.ServiceAPIDescription
63 err = json.Unmarshal(resp, &resAPIs)
65 log.Error("[Get API] error unmarshaling parameter ServiceAPIDescription as JSON")
66 return c.Render(http.StatusBadRequest, "getapi.html", map[string]interface{}{
69 "response": "error unmarshaling parameter ServiceAPIDescription as JSON",
73 bytes, _ := json.Marshal(resAPIs)
74 log.Infof("[Get API] There are %v ServiceAPIDescription objects available", len(resAPIs))
75 return c.Render(http.StatusOK, "getapi.html", map[string]interface{}{
77 "response": string(bytes),