|
1 | 1 | # TypedRest for Java
|
2 | 2 |
|
3 |
| -[](https://dotnet.typedrest.net/) |
4 | 3 | [](https://ci.appveyor.com/project/TypedRest/typedrest-java)
|
5 |
| -TypedRest helps you build type-safe fluent-style REST API clients. |
| 4 | +TypedRest helps you build type-safe, fluent-style REST API clients. |
6 | 5 |
|
7 |
| -Maven artifacts (group `com.oneandone`): |
8 |
| -[](https://mvnrepository.com/artifact/com.oneandone/typedrest-annotations) |
9 |
| -[](https://mvnrepository.com/artifact/com.oneandone/typedrest-core) |
10 |
| -[](https://mvnrepository.com/artifact/com.oneandone/typedrest-vaadin) |
11 |
| -[](https://mvnrepository.com/artifact/com.oneandone/typedrest-archetype) |
12 |
| - |
13 |
| -**Important:** [Lombok](https://projectlombok.org/), a build-time dependency, does not support Java 10 yet. However, the resulting artifact will work on Java 10. |
14 |
| - |
15 |
| - |
16 |
| -## Nomenclature |
17 |
| - |
18 |
| -We use the following terms in the library and documentation: |
19 |
| -* An __entity__ is a data transfer object that can be serialized (usually as JSON). |
20 |
| -* An __endpoint__ is a REST resource at a specific URI. |
21 |
| -* An __entry endpoint__ is an _endpoint_ that is the top-level URI of a REST interface. |
22 |
| -* An __element endpoint__ is an _endpoint_ that represents a single _entity_. |
23 |
| -* A __collection endpoint__ is an _endpoint_ that represents a collection of _entities_ and provides an _element endpoint_ for each of them. |
24 |
| -* A __trigger endpoint__ is an _endpoint_ that represents an RPC call to trigger a single action (intentionally un-RESTful). |
| 6 | +Common REST patterns such as collections are represented as classes, allowing you to write more idiomatic code. For example, TypedRest lets you turn this: |
25 | 7 |
|
| 8 | +```java |
| 9 | +HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://example.com/contacts/123")).build(); |
| 10 | +HttpResponse<> response = HttpClient.newHttpClient().send(request, BodyHandlers.ofString()); |
| 11 | +Contact contact = objectMapper.readValue(response.body(), Contact.class); |
| 12 | +``` |
26 | 13 |
|
27 |
| -## Usecase sample |
| 14 | +into this: |
28 | 15 |
|
29 |
| -We'll use this simple POJO (Plain old Java object) class modeling software packages as a sample _entity_ type: |
30 | 16 | ```java
|
31 |
| -class PackageEntity { |
32 |
| - private int id; |
33 |
| - @Id public int getId() { return id; } |
34 |
| - public void setId(int id) { this.id = id; } |
35 |
| - |
36 |
| - private String name; |
37 |
| - public String getName() { return name; } |
38 |
| - public void setName(String name) { this.name = name; } |
39 |
| -} |
| 17 | +MyServiceClient myService = new MyServiceClient(URI.create("http://example.com/")); |
| 18 | +Contact contact = myService.getContacts().get("123").read(); |
40 | 19 | ```
|
41 | 20 |
|
| 21 | +## Maven artifacts |
42 | 22 |
|
43 |
| -## Getting started |
| 23 | +Artifact group: `com.oneandone` |
44 | 24 |
|
45 |
| -Include this in your Maven ```pom.xml``` to use the library: |
46 |
| -```xml |
47 |
| -<dependency> |
48 |
| - <groupId>com.oneandone</groupId> |
49 |
| - <artifactId>typedrest-core</artifactId> |
50 |
| - <version>0.30</version> |
51 |
| -</dependency> |
52 |
| -``` |
| 25 | +[](https://mvnrepository.com/artifact/com.oneandone/typedrest-core) |
| 26 | +The main TypedRest library. |
53 | 27 |
|
54 |
| -You can then use the classes `EntryEndpoint`, `CollectionEndpointImpl`, `ElementEndpointImpl`, `PollingEndpointImpl`, `ActionEndpointImpl`, `PaginationEndpointImpl`, `StreamEndpointImpl` and `BlobEndpointImpl` to build a local representation of a remote REST service. Based on our usecase sample this could look like this: |
55 |
| -```java |
56 |
| -class SampleEntryEndpoint extends EntryEndpoint { |
57 |
| - public SampleEntryEndpoint(URI uri) { |
58 |
| - super(uri); |
59 |
| - } |
| 28 | +[](https://mvnrepository.com/artifact/com.oneandone/typedrest-annotations) |
| 29 | +Annotations for data models to be used with TypedRest. |
60 | 30 |
|
61 |
| - public CollectionEndpoint<PackageEntity> getPackages() { |
62 |
| - return new CollectionEndpointImpl<>(this, "packages", PackageEntity.class); |
63 |
| - } |
64 |
| -} |
65 |
| -``` |
| 31 | +[](https://mvnrepository.com/artifact/com.oneandone/typedrest-vaadin) |
| 32 | +Build [Vaadin](https://vaadin.com/) GUIs for TypedRest clients. |
66 | 33 |
|
67 |
| -You can then perform CRUD operations like this: |
68 |
| -```java |
69 |
| -SampleEntryEndpoint server = new SampleEntryEndpoint(URI.create("http://myservice/api/")); |
70 |
| -List<PackageEntity> packages = server.packages.readAll(); |
71 |
| -ElementEndpoint<PackageEntity> element = server.packages.create(new PackageEntity(...)); |
72 |
| -PackageEntity pack = server.packages.get(1).read(); |
73 |
| -server.Packages.get(1).update(pack); |
74 |
| -server.Packages.get(1).delete(); |
75 |
| -``` |
| 34 | +[](https://mvnrepository.com/artifact/com.oneandone/typedrest-archetype) |
| 35 | +[Maven archetype](https://maven.apache.org/guides/introduction/introduction-to-archetypes.html) (template) for creating TypedRest projects. |
76 | 36 |
|
77 | 37 |
|
78 |
| -## Build GUI clients |
| 38 | +## Documentation |
79 | 39 |
|
80 |
| -Include this in your Maven ```pom.xml``` to build GUIs with [Vaadin](https://vaadin.com/): |
81 |
| -```xml |
82 |
| -<dependency> |
83 |
| - <groupId>com.oneandone</groupId> |
84 |
| - <artifactId>typedrest-vaadin</artifactId> |
85 |
| - <version>0.27</version> |
86 |
| -</dependency> |
87 |
| -``` |
| 40 | +Read an **[Introduction](https://typedrest.net/introduction/)** to TypedRest or jump right in with the **[Getting started](https://typedrest.net/getting-started/java/)** guide. |
| 41 | + |
| 42 | +For information about specific classes or interfaces you can read the **[API Documentation](https://java.typedrest.net/)**. |
0 commit comments