Skip to content

Repository files navigation

Halbuilder is a simple Java API for generating and consuming HAL documents conforming to the HAL Specification.

traviscodecov

Generating Local Resources

Map<String,Object> friend = HashMap.of("name", "Mike", "age", 36);
ResourceRepresentation<Map<String,Object>> owner =
ResourceRepresentation.create("http://example.com/mike", friend)
.withLink("td:friend", "http://example.com/mamund")
Map<String,Object> todoMeta = HashMap.of(
"created_at", "2010-01-16", "updated_at", "2017-06-13",
"summary", "An example list");
ResourceRepresentation<Map<String,Object>> halResource =
ResourceRepresentation.create("http://example.com/todo-list", todoMeta)
.withLink("td:search", "/todo-list/search;{searchterm}")
.withLink("td:description", "/todo-list/description")
.withRepresentation("td:owner", owner);
JsonRepresentationWriterjsonRepresentationWriter =
JsonRepresentationWriter.create();
ByteStringrepresentation = jsonRepresentationWriter.print(accountRepWithLinks);
System.out.println(representation.utf8());

Reading Local Resources

JsonRepresentationReaderjsonRepresentationReader =
JsonRepresentationReader.create();
ResourceRepresentation<ByteString> representation =
jsonRepresentationReader.read(
newInputStreamReader(Some.class.getResourceAsStream("/test.json")));
// or as a typeResourceRepresentation<Person> personRepresentation =
jsonRepresentationReader.read(
newInputStreamReader(Some.class.getResourceAsStream("/test.json")),
Person.class);

Apache Maven

HalBuilder is deployed to Apache Maven Central under the following coordinates:

<dependency>
<groupId>com.theoryinpractise</groupId>
<artifactId>halbuilder5</artifactId>
<version>5.0.1</version>
</dependency>

Website

More documentation is available from the main website at gotohal.net.

Development Forum

Email support and discussion is available on the development forum.

About

HalBuilder Core

Resources

Stars

40 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages