Open philipliou opened 10 years ago
Ah nevermind it was a newb Go mistake. Imported halgo and did it like this worked:
student.Links = halgo.Links{}.Self("/students/123")
Actually, is there any way to do this:
studentA.Links = halgo.Links{}
studentA.Links.Self("/students/123")
studentA.Links.Link("school", "/schools/456")
It doesn't seem to generate any links. It only works if I chain at least one method after the initializer, halgo.Links{}, like
halgo.links{}.Link("school", "/school/456")
Just a comment. If you perform a POST
and a new resource is created, the POST
response should include a Location
header to the new resource. That is the standard way to pick up new URLs for new resources (HAL or otherwise). I've submitted a pull request (#6) that adds a new method, Location
, that allows you to construct a new navigator
instance from a http.Response
that includes a Location
header.
@philipliou...since my pull request was accepted, should this be closed? Is it sufficient for you?
For example, I want to "generate" the HAL links after I retrieve the resource from my database and convert it to a golang struct. I tried something like:
Now, when I get the Student instance from my database, only the Id, Name, and School fields are populated. But now I want to generate the halgo.Links before I convert to JSON and send it back to client in the response. How would I do that?
I tried something like this:
But I'm getting these errors: