Skip to content

Commit 4b7b470

Browse files
authored
docs: add readme (#56)
1 parent deaf972 commit 4b7b470

File tree

1 file changed

+137
-5
lines changed

1 file changed

+137
-5
lines changed

README.md

Lines changed: 137 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,141 @@
1-
# litmus-java-sdk
1+
# Litmus Java SDK
22

3-
Compatible only with Litmus version 3.13.0
3+
[![Slack Channel](https://img.shields.io/badge/Slack-Join-purple)](https://slack.litmuschaos.io)
4+
[![GitHub issues](https://img.shields.io/github/issues/litmuschaos/litmus-go)](https://github.com/litmuschaos/litmus-go/issues)
5+
[![Twitter Follow](https://img.shields.io/twitter/follow/litmuschaos?style=social)](https://twitter.com/LitmusChaos)
6+
[![YouTube Channel](https://img.shields.io/badge/YouTube-Subscribe-red)](https://www.youtube.com/channel/UCa57PMqmz_j0wnteRa9nCaw)
7+
<br><br>
48

5-
## TBD
9+
## **Introduction**
610

7-
## Contributing to litmus-java-sdk
11+
The Litmus Java SDK makes it easy to communicate with Litmus’ internal servers.
812

9-
Check out the [CONTRIBUTING.md](./CONTRIBUTING.md)
13+
## Requirements
14+
15+
This library requires Java 17 or later.
16+
17+
Litmus version 3.13.0 or later.
18+
19+
## Installation
20+
21+
### Gradle example
22+
23+
```groovy
24+
implementation 'io.litmuschaos:litmus-sdk:<VERSION>'
25+
```
26+
27+
### Maven example
28+
29+
```xml
30+
<dependency>
31+
<groupId>io.litmuschaos</groupId>
32+
<artifactId>litmus-sdk</artifactId>
33+
<version>VERSION</version>
34+
</dependency>
35+
```
36+
37+
## LitmusClient
38+
39+
LitmusClient contains simple, easy-to-use interface for making requests to litmus internal servers.
40+
41+
```java
42+
import io.litmuschaos.LitmusClient;
43+
import io.litmuschaos.request.UserCreateRequest;
44+
import io.litmuschaos.response.UserResponse;
45+
46+
String host = "http://localhost:3000"; // LitmusChaos frontend url
47+
String token = "eyJhbGciOiJIUzUxMiIsInR..." // api token
48+
49+
LitmusClient litmusClient = new LitmusClient(host, token);
50+
51+
UserCreateRequest request = UserCreateRequest.builder()
52+
.username("litmus")
53+
.password("passwd")
54+
.role("user")
55+
56+
.build();
57+
58+
UserResponse response = litmusClient.createUser(request);
59+
```
60+
61+
You can customize httpClient configuration by injecting `LitmusConfig` class.
62+
63+
```java
64+
LitmusConfig config = new LitmusConfig();
65+
66+
config.setHttpClientReadTimeoutMillis(1000L);
67+
config.setHttpClientWriteTimeoutMillis(1000L);
68+
config.setHttpClientConnectTimeoutMillis(1000L);
69+
70+
LitmusClient litmusClient = new LitmusClient("host", "token", config);
71+
72+
// if you don't need to set custom properties, just pass host and token.
73+
// Default configurations are applied.
74+
LitmusClient litmusClient = new LitmusClient("host", "token");
75+
```
76+
77+
## How to use ProjectionRoot
78+
79+
You need to understand `projectionRoot` for using Litmus Java SDK well. When you access to litmus graphQL backend server by SDK, you can filter response field by projectionRoot.
80+
81+
```java
82+
GetEnvironmentGraphQLQuery query = new GetEnvironmentGraphQLQuery.Builder()
83+
.projectID("567ccf04-7195-4311-a215-0803fe5e93f6")
84+
.environmentID("test-environments")
85+
.build();
86+
87+
GetEnvironmentProjectionRoot projectionRoot = new GetEnvironmentProjectionRoot<>()
88+
.projectID()
89+
.createdBy().userID().username().root()
90+
.name()
91+
.updatedBy().userID().username().root();
92+
93+
Environment response = litmusClient.getEnvironment(query, projectionRoot);
94+
```
95+
litmusClient only return fields that selected by projectionRoot.
96+
```
97+
{
98+
projectID="567ccf04-7195-4311-a215-0803fe5e93f6",
99+
name="test",
100+
createdBy={
101+
userID="567ccf04-7195-4311",
102+
username="test-user",
103+
email=null // not selected
104+
}
105+
description=null, // not selected
106+
tags=null, // not selected
107+
...
108+
}
109+
```
110+
111+
ProjectionRoot is tree data structure, so you can explore object graph by `parent()` and `root()` method.
112+
113+
- parent() : move to upper position
114+
- root() : move to root position
115+
116+
```
117+
{
118+
"name": "test",
119+
"faultName": "test fault",
120+
"executedByExperment": {
121+
"experimentID": "test-id",
122+
"experimentName": "test-experiment",
123+
"updatedBy": {
124+
"username": "test-user", // If you call parent() here, you can access to experimentName field
125+
"email": "[email protected]" // If you call root() here, you can access to faultName field
126+
}
127+
}
128+
}
129+
```
130+
131+
## **Sample code**
132+
133+
This project contains the following [sample code](https://github.com/litmuschaos/litmus-java-sdk/blob/master/src/test/java/io/litmuschaos/LitmusClientTest.java)
134+
135+
## **Contributing**
136+
137+
We'd love to have you contribute! Please refer to [CONTRIBUTING](./CONTRIBUTING.md) for details.
138+
139+
## License
140+
141+
Here is a copy of the License: [License](./LICENSE)

0 commit comments

Comments
 (0)