Skip to content

Commit f9f8f23

Browse files
committed
README: Add a diagram
1 parent 9724059 commit f9f8f23

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

README.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ Check out [this template repository](https://github.com/axel-op/agnostic-serverl
1616

1717
## Usage
1818

19+
<p align="center"><img src="./diagram.png" width=400></p>
20+
21+
### Code
22+
23+
The class containing the agnostic function must implement the [`Handler`](./interfaces/src/main/java/fr/axelop/agnosticserverlessfunctions/Handler.java) interface. It must be [registered as a *service provider*](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.html) so it can be loaded with a `ServiceLoader`. This means that there must be a resource file `META-INF/services/fr.axelop.agnosticserverlessfunctions.Handler` containing the fully qualified binary name of your handler class (in this example, it would be `com.example.MyHandler`). You can automate this process by using the [Google @AutoService](https://github.com/google/auto/tree/master/service) annotation.
24+
25+
There can only be one handler in your JAR.
26+
27+
```java
28+
package com.example;
29+
30+
import java.util.logging.Logger;
31+
32+
import fr.axelop.agnosticserverlessfunctions.Handler;
33+
import fr.axelop.agnosticserverlessfunctions.HttpRequest;
34+
import fr.axelop.agnosticserverlessfunctions.HttpResponse;
35+
36+
public class MyHandler implements Handler {
37+
38+
@Override
39+
public HttpResponse handle(HttpRequest request, Logger logger) {
40+
return HttpResponse.newBuilder()
41+
.setStatusCode(200)
42+
.setBody(request.getBody().isPresent()
43+
? "The request body was: " + request.getBody().get()
44+
: "There was no body in this " + request.getMethod() + " request!")
45+
.build();
46+
}
47+
48+
}
49+
```
50+
1951
### Configuration
2052

2153
You'll need to add two dependencies from [my Maven repository](https://github.com/axel-op/maven-packages):
@@ -51,36 +83,6 @@ You'll need to add two dependencies from [my Maven repository](https://github.co
5183
</project>
5284
```
5385

54-
### Code
55-
56-
The class containing the agnostic function must implement the [`Handler`](./interfaces/src/main/java/fr/axelop/agnosticserverlessfunctions/Handler.java) interface. It must be [registered as a *service provider*](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.html) so it can be loaded with a `ServiceLoader`. This means that there must be a resource file `META-INF/services/fr.axelop.agnosticserverlessfunctions.Handler` containing the fully qualified binary name of your handler class (in this example, it would be `com.example.MyHandler`). You can automate this process by using the [Google @AutoService](https://github.com/google/auto/tree/master/service) annotation.
57-
58-
There can only be one handler in your JAR.
59-
60-
```java
61-
package com.example;
62-
63-
import java.util.logging.Logger;
64-
65-
import fr.axelop.agnosticserverlessfunctions.Handler;
66-
import fr.axelop.agnosticserverlessfunctions.HttpRequest;
67-
import fr.axelop.agnosticserverlessfunctions.HttpResponse;
68-
69-
public class MyHandler implements Handler {
70-
71-
@Override
72-
public HttpResponse handle(HttpRequest request, Logger logger) {
73-
return HttpResponse.newBuilder()
74-
.setStatusCode(200)
75-
.setBody(request.getBody().isPresent()
76-
? "The request body was: " + request.getBody().get()
77-
: "There was no body in this " + request.getMethod() + " request!")
78-
.build();
79-
}
80-
81-
}
82-
```
83-
8486
### Packaging and deployment
8587

8688
These steps are specific to each FaaS provider:

diagram.png

87 KB
Loading

0 commit comments

Comments
 (0)