in whisk/api.go [357:396]
func (s *ApiService) Insert(api *ApiCreateRequest, options *ApiCreateRequestOptions, overwrite bool) (*ApiCreateResponse, *http.Response, error) {
route := "web/whisk.system/apimgmt/createApi.http"
Debug(DbgInfo, "Api PUT route: %s\n", route)
routeUrl, err := addRouteOptions(route, options)
if err != nil {
Debug(DbgError, "addRouteOptions(%s, %#v) error: '%s'\n", route, options, err)
errMsg := wski18n.T("Unable to add route options '{{.options}}'",
map[string]interface{}{"options": options})
whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXIT_CODE_ERR_GENERAL, DISPLAY_MSG,
NO_DISPLAY_USAGE)
return nil, nil, whiskErr
}
Debug(DbgError, "Api create route with options: %s\n", routeUrl)
req, err := s.client.NewRequestUrl("POST", routeUrl, api, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson, AuthRequired)
if err != nil {
Debug(DbgError, "http.NewRequestUrl(POST, %s, nil, DoNotIncludeNamespaceInUrl, AppendOpenWhiskPathPrefix, EncodeBodyAsJson) error: '%s'\n", route, err)
errMsg := wski18n.T("Unable to create HTTP request for POST '{{.route}}': {{.err}}",
map[string]interface{}{"route": route, "err": err})
whiskErr := MakeWskErrorFromWskError(errors.New(errMsg), err, EXIT_CODE_ERR_NETWORK, DISPLAY_MSG,
NO_DISPLAY_USAGE)
return nil, nil, whiskErr
}
retApi := new(ApiCreateResponse)
resp, err := s.client.Do(req, &retApi, ExitWithErrorOnTimeout)
if err != nil {
Debug(DbgError, "s.client.Do() error - HTTP req %s; error '%s'\n", req.URL.String(), err)
return nil, resp, err
}
err = validateApiSwaggerResponse(retApi.Swagger)
if err != nil {
Debug(DbgError, "Not a valid API creation response\n")
return nil, resp, err
}
return retApi, resp, nil
}