Skip to content

Commit e3992c6

Browse files
authored
feat: add more HTTP parameter types (#20)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent 53afbef commit e3992c6

4 files changed

Lines changed: 52 additions & 7 deletions

File tree

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,3 @@ You can visit it via: http://localhost:8080/graphiql?path=/graphql
1717

1818
## tRPC
1919
The [tRPC](https://github.com/trpc-group/trpc-java) endpoint is: `http://localhost:9090`
20-
21-
## OpenAPI
22-
You can visit the swagger UI with the following address:
23-
24-
* https://localhost:8080/swagger-ui/index.html
25-
* https://localhost:8080/v3/api-docs

e2e/test-suite.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ items:
3333
Authorization: "{{ .param.auth }}"
3434
expect:
3535
body: hello
36+
- name: repeat
37+
request:
38+
api: /repeat/3
39+
query:
40+
text: a
41+
header:
42+
Authorization: "{{ .param.auth }}"
43+
expect:
44+
body:
45+
aaa
46+
- name: base64
47+
request:
48+
api: /base64
49+
method: POST
50+
body: |
51+
{
52+
"message":"OK"
53+
}
54+
header:
55+
Authorization: "{{ .param.auth }}"
56+
Content-Type: application/json
57+
expect:
58+
bodyFieldsExpect:
59+
message: T0s=
3660

3761
## Cookies
3862
- name: no-cookie

src/main/java/io/github/devopsws/demo/model/Message.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
public class Message {
44
private String message;
55

6+
// avoid the following error
7+
// JSON parse error: Cannot construct instance of
8+
public Message() {}
9+
610
public Message(String message) {
711
this.message = message;
812
}
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
package io.github.devopsws.demo.service;
22

3+
import java.util.Base64;
4+
35
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
49
import org.springframework.web.bind.annotation.RequestParam;
510
import org.springframework.web.bind.annotation.RestController;
11+
import io.github.devopsws.demo.model.Message;
612

713
@RestController
814
public class StringService {
915
@GetMapping("/lower")
10-
public String lower(@RequestParam(required = true) String text) {
16+
public String lower(@RequestParam(required = true) String text,
17+
@RequestParam(required = false) boolean trim) {
18+
if (trim) {
19+
text=text.trim();
20+
}
1121
return text.toLowerCase();
1222
}
23+
24+
@GetMapping("/repeat/{count}")
25+
public String repeat(@RequestParam(required = true) String text,
26+
@PathVariable int count) {
27+
return text.repeat(count);
28+
}
29+
30+
@PostMapping("/base64")
31+
public Message base64(@RequestBody Message message) {
32+
String encodedString = Base64.getEncoder().encodeToString(message.getMessage().getBytes());
33+
message.setMessage(encodedString);
34+
return message;
35+
}
1336
}

0 commit comments

Comments
 (0)