A generator for siren hypermedia API responses.
var writer = ;var siren = ;var entity =;console;
Creates a new
siren writer with the given
base as the base URL for things
href throughout an entity.
The returned function is the entire API. It returns an object that can be serialized as a JSON response.
// expressres;// koathisbody = ;
Generally-speaking, this API avoids performing magic. It wants you to be explicit, only accepting objects instead of positional arguments. However, there are a few ways that this API improves upon generating the response entirely from scratch:
entitieswhere you could be merging several different types for a single response
relvalues that aren't defined by IANA)
relfor a link
The keys in
options include everything in the spec,
so use that as a reference when building your configuration options. Additional properties will be included, but their behavior with clients cannot be guaranteed. Some other
things to be aware of:
base, especially when using a pathname
/in your relative URLs, as it will behave unexpectedly if your
basehas a pathname as part of it. (ie:
throwexceptions in the cases mentioned previously