Skip to content

Commit ee3740e

Browse files
committed
Added pdf and html docs
1 parent 33e3983 commit ee3740e

File tree

7 files changed

+997
-11
lines changed

7 files changed

+997
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
***The motivation behind porting this is using it for generating snippets in swagger and redocs.
1212
The project is still in development phase***.
1313

14-
- [ ] Documentation
14+
- [x] Documentation
1515
- [x] Tests
1616
- [ ] Releasing to maven
1717

56.4 KB
Loading

docs/index.adoc

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,92 @@
33

44
An HTTP Request snippet generator for many languages & tools. It can generate code for over twelve different languages and currently supports cURL, Javascript, Node, C, Java, Objective-C, Swift, Python, Ruby, C#, Go, OCaml and more!.
55

6+
==== Usage
7+
Enable maven snapshots in `~/.m2/settings.xml`
8+
```xml
9+
<profiles>
10+
<profile>
11+
<id>allow-snapshots</id>
12+
<activation><activeByDefault>true</activeByDefault></activation>
13+
<repositories>
14+
<repository>
15+
<id>snapshots-repo</id>
16+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
17+
<releases><enabled>false</enabled></releases>
18+
<snapshots><enabled>true</enabled></snapshots>
19+
</repository>
20+
</repositories>
21+
</profile>
22+
</profiles>
23+
```
24+
25+
Then add this ```dependency``` to ```pom.xml```
26+
27+
```xml
28+
<dependency>
29+
<groupId>io.github.atkawa7</groupId>
30+
<artifactId>httpsnippet</artifactId>
31+
<version>0.0.1-SNAPSHOT</version>
32+
</dependency>
33+
```
34+
35+
Once you have added this as a dependency then you are ready to generate code snippets.
36+
37+
38+
```java
39+
public class Main {
40+
public static void main(String[] args) throws Exception {
41+
List<HarHeader> headers = new ArrayList<>();
42+
List<HarQueryString> queryStrings = new ArrayList<>();
43+
44+
User user = new User();
45+
Faker faker = new Faker();
46+
user.setFirstName(faker.name().firstName());
47+
user.setLastName(faker.name().lastName());
48+
49+
50+
HarPostData harPostData =
51+
new HarPostDataBuilder()
52+
.withMimeType(MediaType.APPLICATION_JSON)
53+
.withText(ObjectUtils.writeValueAsString(user)).build();
54+
55+
HarRequest harRequest =
56+
new HarRequestBuilder()
57+
.withMethod(HttpMethod.GET.toString())
58+
.withUrl("http://localhost:5000/users")
59+
.withHeaders(headers)
60+
.withQueryString(queryStrings)
61+
.withHttpVersion(HttpVersion.HTTP_1_1.toString())
62+
.withPostData(harPostData)
63+
.build();
64+
65+
//Using default generator for the language
66+
HttpSnippet httpSnippet = new HttpSnippetCodeGenerator().snippet(harRequest, Language.JAVA);
67+
System.out.println(httpSnippet.getCode());
68+
69+
//Or directly using the generator
70+
String code = new OkHttp().code(harRequest);
71+
System.out.println(code);
72+
73+
}
74+
75+
@Data
76+
static class User {
77+
private String firstName;
78+
private String lastName;
79+
}
80+
}
81+
```
82+
83+
84+
For integrating with other third party i.e ```spring```, ```redoc```, ```swagger``` such as checkout the demo.
85+
86+
```bash
87+
https://github.com/atkawa7/httpsnippet
88+
cd httpsnippet
89+
mvn clean install
90+
java -jar httpsnippet-demo/target/httpsnippet-demo-0.0.1-SNAPSHOT.jar
91+
```
692

793
==== Har Request
894

@@ -109,7 +195,7 @@ then it will be merged into a new list and the resulting url in code snippets wi
109195

110196
==== Generators
111197

112-
Please start by browsing for available generators and inspect each implementation. A generator is a simple module with a constructor that accepts two parameters: language and client where language is the target language i.e ```JAVA```, ```PYTHON``` and client is the target client that supports the language ```OKHTTP``` for ```JAVA```. The generator has ```generateCode``` function which converts ```HarRequest``` to ```HttpSnippet```.
198+
Please start by browsing for available generators and inspect each implementation. A generator is a simple class with a constructor that accepts two parameters: language and client where language is the target language i.e ```JAVA```, ```PYTHON``` and client is the target client that supports the language ```OKHTTP``` for ```JAVA```. The generator has ```generateCode``` function which converts ```HarRequest``` to ```HttpSnippet```.
113199

114200
[plantuml, generators]
115201
....

0 commit comments

Comments
 (0)