Skip to content

Commit 5f46ea5

Browse files
authored
Merge pull request #117 from SentryMan/SentryMan-patch-1
Bring the README more in line with the Docs
2 parents b4a3ccf + e902d91 commit 5f46ea5

File tree

1 file changed

+68
-39
lines changed

1 file changed

+68
-39
lines changed

README.md

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# avaje-http
1+
# [Avaje-HTTP](https://avaje.io/http/)
2+
[![Build](https://github.com/avaje/avaje-http/actions/workflows/build.yml/badge.svg)](https://github.com/avaje/avaje-http/actions/workflows/build.yml)
3+
<img src="https://img.shields.io/maven-central/v/io.avaje/avaje-http-api.svg?label=Maven%20Central">
4+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/avaje/avaje-inject/blob/master/LICENSE)
25

36
HTTP server and client libraries via code generation.
47

5-
Documentation at [avaje.io/http](https://avaje.io/http/)
6-
## Http Server
8+
## HTTP Server
79

810
A jax-rs style controllers with annotations (`@Path`, `@Get` ...)
911
that is lightweight by using source code generation (annotation processors)
@@ -13,37 +15,59 @@ to generate adapter code for Javalin and Helidon SE/Nima.
1315
- Full use of Javalin or Helidon SE/Nima as desired
1416

1517
## Add dependencies
16-
1718
```xml
19+
<dependency>
20+
<groupId>io.avaje</groupId>
21+
<artifactId>avaje-inject</artifactId>
22+
<version>${avaje-inject.version}</version>
23+
</dependency>
1824
<dependency>
1925
<groupId>io.avaje</groupId>
2026
<artifactId>avaje-http-api</artifactId>
2127
<version>${avaje.http.version}</version>
2228
</dependency>
2329
```
24-
Add the generator module for your desired microframework as a annotation processor.
30+
#### Add the generator module for your desired microframework as a annotation processor.
2531

2632
```xml
27-
<build>
28-
<plugins>
29-
<plugin>
30-
<groupId>org.apache.maven.plugins</groupId>
31-
<artifactId>maven-compiler-plugin</artifactId>
32-
<version>${maven-compiler-plugin.version}</version>
33-
<configuration>
34-
<annotationProcessorPaths>
35-
<path>
36-
<groupId>io.avaje</groupId>
37-
<artifactId>avaje-http-javalin-generator</artifactId>
38-
<version>${avaje.http.version}</version>
39-
</path>
40-
</annotationProcessorPaths>
41-
</configuration>
42-
</plugin>
43-
</plugins>
44-
</build>
33+
<!-- Annotation processors -->
34+
<dependency>
35+
<groupId>io.avaje</groupId>
36+
<artifactId>avaje-inject-generator</artifactId>
37+
<version>${avaje-inject.version}</version>
38+
<scope>provided</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>io.avaje</groupId>
42+
<artifactId>avaje-http-javalin-generator</artifactId>
43+
<version>${avaje-http.version}</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
```
47+
If there are other annotation processors and they are specified via <i>maven-compiler-plugin</i> then we add avaje-http-generator there instead.
48+
```xml
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<configuration>
53+
<annotationProcessorPaths> <!-- All annotation processors specified here -->
54+
<path>
55+
<groupId>io.avaje</groupId>
56+
<artifactId>avaje-inject-generator</artifactId>
57+
<version>${avaje-inject.version}</version>
58+
</path>
59+
<path>
60+
<groupId>io.avaje</groupId>
61+
<artifactId>avaje-http-javalin-generator</artifactId>
62+
<version>${avaje-http.version}</version>
63+
</path>
64+
<path>
65+
... other annotation processor ...
66+
</path>
67+
</annotationProcessorPaths>
68+
</configuration>
69+
</plugin>
4570
```
46-
4771
## Define a Controller (These APT processors work with both Java and Kotlin.)
4872
```java
4973
package org.example.hello;
@@ -60,7 +84,7 @@ public class WidgetController {
6084
public WidgetController(HelloComponent hello) {
6185
this.hello = hello;
6286
}
63-
87+
6488
@Get("/{id}")
6589
Widget getById(int id) {
6690
return new Widget(id, "you got it"+ hello.hello());
@@ -75,26 +99,31 @@ public class WidgetController {
7599
}
76100
```
77101

78-
## Usage with Javalin
102+
## Usage
103+
The annotation processor will generate controller adapters that can register routes to Javalin/Helidon. The natural way to use the generated adapters is to get a DI library to find and wire them. This is what the below examples do and they use [Avaje-Inject](https://avaje.io/inject/) to do this.
104+
105+
Note that there isn't a requirement to use Avaje for dependency injection. Any DI library that can find and wire the generated @Singleton beans can be used. You can even use Dagger2 or Guice to wire the controllers if you so desire.
106+
107+
### Usage with Javalin
79108

80109
The annotation processor will generate controller classes implementing the WebRoutes interface, which means we can
81110
get all the WebRoutes and register them with Javalin using:
82111

83112
```java
84-
var routes = BeanScope.builder().build().list(WebRoutes.class);
113+
var routes = BeanScope.builder().build().list(WebRoutes.class);
85114

86115
Javalin.create()
87116
.routes(() -> routes.forEach(WebRoutes::registerRoutes))
88117
.start();
89118
```
90119

91-
## Usage with Helidon SE
120+
### Usage with Helidon SE
92121

93122
The annotation processor will generate controller classes implementing the Helidon Service interface, which we can use
94123
get all the Services and register them with Helidon `RoutingBuilder`.
95124

96125
```java
97-
var routes = BeanScope.builder().build().list(Service.class);
126+
var routes = BeanScope.builder().build().list(Service.class);
98127
var routingBuilder = Routing.builder().register(routes.stream().toArray(Service[]::new));
99128
WebServer.builder()
100129
.addMediaSupport(JacksonSupport.create())
@@ -103,13 +132,13 @@ WebServer.builder()
103132
.start();
104133
```
105134

106-
## Usage with Helidon Nima
135+
### Usage with Helidon Nima
107136

108137
The annotation processor will generate controller classes implementing the Helidon HttpService interface, which we can use
109138
get all the services and register them with the Helidon `HttpRouting`.
110139

111140
```java
112-
var routes = BeanScope.builder().build().list(HttpService.class);
141+
var routes = BeanScope.builder().build().list(HttpService.class);
113142
final var builder = HttpRouting.builder();
114143

115144
for (final HttpService httpService : routes) {
@@ -232,13 +261,13 @@ If [Avaje-Jsonb](https://github.com/avaje/avaje-jsonb) is detected, http generat
232261
public class WidgetController$Route implements WebRoutes {
233262

234263
private final WidgetController controller;
235-
private final JsonType<java.util.List<org.example.hello.WidgetController.Widget>> listWidgetJsonType;
236-
private final JsonType<org.example.hello.WidgetController.Widget> widgetJsonType;
264+
private final JsonType<List<Widget>> listWidgetJsonType;
265+
private final JsonType<Widget> widgetJsonType;
237266

238267
public WidgetController$Route(WidgetController controller, Jsonb jsonB) {
239268
this.controller = controller;
240-
this.listWidgetJsonType = jsonB.type(org.example.hello.WidgetController.Widget.class).list();
241-
this.widgetJsonType = jsonB.type(org.example.hello.WidgetController.Widget.class);
269+
this.listWidgetJsonType = jsonB.type(Widget.class).list();
270+
this.widgetJsonType = jsonB.type(Widget.class);
242271
}
243272

244273
@Override
@@ -271,13 +300,13 @@ public class WidgetController$Route implements HttpService {
271300

272301

273302
private final WidgetController controller;
274-
private final JsonType<org.example.hello.WidgetController.Widget> widgetJsonType;
275-
private final JsonType<java.util.List<org.example.hello.WidgetController.Widget>> listWidgetJsonType;
303+
private final JsonType<Widget> widgetJsonType;
304+
private final JsonType<List<Widget>> listWidgetJsonType;
276305

277306
public WidgetController$Route(WidgetController controller, Jsonb jsonB) {
278307
this.controller = controller;
279-
this.widgetJsonType = jsonB.type(org.example.hello.WidgetController.Widget.class);
280-
this.listWidgetJsonType = jsonB.type(org.example.hello.WidgetController.Widget.class).list();
308+
this.widgetJsonType = jsonB.type(Widget.class);
309+
this.listWidgetJsonType = jsonB.type(Widget.class).list();
281310
}
282311

283312
@Override

0 commit comments

Comments
 (0)