Does anyone have any examples on how to connect backend and fronted please?
I know I need to send data using:
template.ExecuteTemplate(w, "index/html, data)
But I created my Api using MongoDB and I don’t know how to do it right
I just want to send that JSON to the front, I tried for example some func:
r , err := htpp.Get("localhost:3000/users")
if err != nil {
panic (err)
}
defer r.Body.Close()
body, err := io.ReadAll(r.Body)
if err != nil {
panic (err)
}
var users [ ]models.User = make([ ]models.User, 0)
json.Unmarshal(body, &users)
template.ExecuteTemplate(w, "index/html, users)
fmt.Println(string(body)) //here I have the correct data
fmt.Println(users) //I have no data here