README.md 5.68 KB
Newer Older
Andreas Lauer's avatar
Andreas Lauer committed
1
2
# Delight: Json over HTTP

Andreas Lauer's avatar
Andreas Lauer committed
3
4
5
6
This Delight backend implementation offers JSON-based RPC calls to simple Java objects implementing Java interfaces or abstract Java classes.

The interface (or abstract class) is used to forge requests from __easy-to-use Java clients__ to the server. Non-java clients profit from
the simple HTTP-request format which is also browser __browser-friendly__.
Andreas Lauer's avatar
Andreas Lauer committed
7
 
Andreas Lauer's avatar
Andreas Lauer committed
8
9
10
11
12
13
14
15
16
17
18
19
20
## How it works

Define a Java-Interface, for example

        public interface ServiceApi {
           String doSometing(TestPojo parameter);
        }
e.g., with a self-defined bean named `TestPojo`

        public class TestPojo {
           int number; 
           String string;
        } 
Andreas Lauer's avatar
Andreas Lauer committed
21
22
23
24
25
26
27
28

and a simple implementation of the interface (this is called a handler)

       public class ServiceImpl implements ServiceApi {
           public String doSometing(TestPojo parameter) {
                return "Just received " + parameter;
           }
       }
Andreas Lauer's avatar
Andreas Lauer committed
29
    
Andreas Lauer's avatar
Andreas Lauer committed
30
Then you can register the implementation with the Delight backend.
Andreas Lauer's avatar
Andreas Lauer committed
31
32
33

        DelightConfig cfg = DelightConfigFinder.getDefaultConfig()
        DelightServer server = new DelightServer(cfg)
34
            .port( $PORT )             //e.g., 8080
35
            .contextPath( $ROOT_PATH ) //e.g., "/delight"
Andreas Lauer's avatar
Andreas Lauer committed
36
37
38
39
40
41
42
43
            .init( backend -> {
                backend.addHandlerByClass("handler-x", ServiceImpl.class);
            });
        server.start();
        server.waitForShutdown();
    
Now you can do RPC calls to this backend with any tool which is able to send HTTP requests.

44
45
Assuming a start on mypc, port 8080 and a root path of "/delight" the endpoint URL will be `http://mypc:8080/delight`

Andreas Lauer's avatar
Andreas Lauer committed
46
See the example server startup code here: [ExampleServer](/../../wikis/ExampleServer)
Andreas Lauer's avatar
Andreas Lauer committed
47

Andreas Lauer's avatar
Andreas Lauer committed
48
49
50
51
52
### Java Client

Using the service from a Java client is as easy as

        Delight delight = new Delight(DelightConfigFinder.getDefaultConfig());
53
        ServiceApi client = delight.connectingTo($ROOT_URL)   //e.g. "http://localhost:8080/delight"
Andreas Lauer's avatar
Andreas Lauer committed
54
55
56
57
58
                                   .usingApi("handler-x", ServiceApi.class);
        String retVal = client.soDomething( new TestPojo(...) );

Delight will take care of object serialization out-of-the-box

Andreas Lauer's avatar
Andreas Lauer committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
## Maven Dependency

### Repository

Releases

        <repository>
            <id>delight-releases</id>
            <url>http://www.dfki.uni-kl.de/artifactory/libs-releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
       
Snapshots 
        
        <repository>
            <id>delight-snapshots</id>
            <url>http://www.dfki.uni-kl.de/artifactory/libs-snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>

Andreas Lauer's avatar
Andreas Lauer committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
### Current Version
        <properties>
            <delight.version>4.0-SNAPSHOT</delight.version>
        </properties>
    
    
### Coordinate

        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>json-over-http-delight</artifactId>
            <version>${delight.version}</version>
        </dependency>

Andreas Lauer's avatar
Andreas Lauer committed
104
        
Andreas Lauer's avatar
Andreas Lauer committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
### Features

#### Online Documentation

Provide online documentation of registered handlers, provided methods and enabled features.
(recommended)

        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>doc-delight-feature</artifactId>
            <version>${delight.version}</version>
        </dependency>


Andreas Lauer's avatar
Andreas Lauer committed
119
[detailed description](/../../wikis/DocuFeature)
Andreas Lauer's avatar
Andreas Lauer committed
120
121
122
123
124

#### Call Statistics

Log statistics of requested server methods

125
126
127
128
129
130
        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>stats-delight-feature</artifactId>
            <version>${delight.version}</version>
        </dependency>

Andreas Lauer's avatar
Andreas Lauer committed
131
[detailed description](/../../wikis/StatsFeature)
Andreas Lauer's avatar
Andreas Lauer committed
132
133
134
135
136

#### Server Sent Events

Use Server-Sent Events through standard Delight calls.

137
138
139
140
141
142
        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>sse-delight-feature</artifactId>
            <version>${delight.version}</version>
        </dependency>

Andreas Lauer's avatar
Andreas Lauer committed
143
[detailed description](/../../wikis/ServerSentEventsFeature)
Andreas Lauer's avatar
Andreas Lauer committed
144
145
146
147
148
149
150


#### Pre-Compiled Clients in a Micro Maven Repository

Provide a readily compiled client that is served through a Maven repository 
also provided by the feature.

151
152
153
154
155
156
        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>mvnmicrorepo-delight-feature</artifactId>
            <version>${delight.version}</version>
        </dependency>

Andreas Lauer's avatar
Andreas Lauer committed
157
[detailed description](/../../wikis/MavenMicroRepoFeature)
Andreas Lauer's avatar
Andreas Lauer committed
158

Andreas Lauer's avatar
Andreas Lauer committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
### Additional Support

#### Use Abstract Classes as Service Interfaces

Adding this artifact to the classpath allows abstract Java classes as service interfaces.

        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>class-proxy-support</artifactId>
            <version>${delight.version}</version>
        </dependency>

#### RxJava Wrappers for Server-Sent Events

Wrappers allow to make event streams `Observable` or make an event stream an `Oberserver` to
some backend event source. 

        <dependency>
            <groupId>dfki.km.delight</groupId>
            <artifactId>sse-rxjava-delight-support</artifactId>
            <version>${delight.version}</version>
        </dependency>

Andreas Lauer's avatar
Andreas Lauer committed
182

Andreas Lauer's avatar
Andreas Lauer committed
183
Go to the >>> [Wiki](/../../wikis/Home) <<< for documentation
Andreas Lauer's avatar
Andreas Lauer committed
184

Andreas Lauer's avatar
Andreas Lauer committed
185
## Licence
Andreas Lauer's avatar
Andreas Lauer committed
186

Andreas Lauer's avatar
Andreas Lauer committed
187
[GNU Lesser General Public License v3](https://www.gnu.org/licenses/lgpl.html)
Andreas Lauer's avatar
Andreas Lauer committed
188

Andreas Lauer's avatar
Andreas Lauer committed
189
190
191
## Legal & Data Protection

[Privacy Policy & Legal Notice](https://config.opendfki.de/imprint)