Permalink
Newer
Older
100644 40 lines (28 sloc) 1.49 KB
Feb 9, 2012
1
Halbuilder is a simple Java API for generating and consuming HAL documents conforming to the
Oct 15, 2011
2
[HAL Specification](http://stateless.co/hal_specification.html).
3
Feb 9, 2012
4
### Generating Local Resources
5
Feb 9, 2012
6
ResourceFactory resourceFactory = new ResourceFactory();
7
8
Resource owner = resourceFactory.newResource("http://example.com/mike")
Oct 15, 2011
9
.withLink("td:friend", "http://example.com/mamund")
10
.withProperty("name", "Mike")
11
.withProperty("age", "36");
12
13
Resource halResource = resourceFactory.newResource("http://example.com/todo-list")
Oct 15, 2011
14
.withNamespace("td", "http://example.com/todoapp/rels/")
15
.withLink("td:search", "/todo-list/search;{searchterm}")
16
.withLink("td:description", "/todo-list/description")
17
.withProperty("created_at", "2010-01-16")
18
.withProperty("updated_at", "2010-02-21")
19
.withProperty("summary", "An example list")
20
.withSubresource("td:owner", owner);
21
22
String xml = halResource.renderContent(ResourceFactory.HAL_XML);
23
String json = halResource.renderContent(ResourceFactory.HAL_JSON);
Feb 9, 2012
24
Feb 9, 2012
25
### Reading Local Resources
26
27
ResourceFactory resourceFactory = new ResourceFactory();
28
29
Resource resource = resourceFactory.newResource(new InputStreamReader(Some.class.getResourceAsStream("/test.xml")));
30
31
### Apache Maven
32
33
HalBuilder is deployed to Apache Maven Central under the following coordinates:
34
35
<dependency>
36
<groupId>com.theoryinpractise</groupId>
37
<artifactId>halbuilder</artifactId>
38
<version>1.0.3</version>
39
</dependency>