|
1 | 1 | package org.example; |
2 | 2 |
|
3 | | -import io.avaje.http.api.*; |
4 | | -import io.helidon.common.http.HttpMediaType; |
5 | | -import io.helidon.nima.webserver.http.ServerRequest; |
6 | | -import io.helidon.nima.webserver.http.ServerResponse; |
7 | | - |
8 | 3 | import java.util.List; |
9 | 4 | import java.util.Map; |
10 | 5 | import java.util.Set; |
11 | 6 |
|
| 7 | +import io.avaje.http.api.Controller; |
| 8 | +import io.avaje.http.api.Form; |
| 9 | +import io.avaje.http.api.Get; |
| 10 | +import io.avaje.http.api.MediaType; |
| 11 | +import io.avaje.http.api.Post; |
| 12 | +import io.avaje.http.api.Produces; |
| 13 | +import io.avaje.http.api.Put; |
| 14 | +import io.helidon.common.http.HttpMediaType; |
| 15 | +import io.helidon.nima.webserver.http.ServerRequest; |
| 16 | +import io.helidon.nima.webserver.http.ServerResponse; |
| 17 | + |
12 | 18 | @Controller |
13 | 19 | public class HelloController { |
14 | 20 |
|
@@ -47,7 +53,13 @@ Person person(String name) { |
47 | 53 | return new Person(42, name + " hello"); |
48 | 54 | } |
49 | 55 |
|
50 | | - // curl -X POST http://localhost:8081/person -H 'Content-Type: application/json' -d '{"id":942,"name":"Jimmy"}' |
| 56 | + @Get("person/{long}") |
| 57 | + Person testLong(long id) { |
| 58 | + return new Person(id, "Giorno hello"); |
| 59 | + } |
| 60 | + |
| 61 | + // curl -X POST http://localhost:8081/person -H 'Content-Type: application/json' -d |
| 62 | + // '{"id":942,"name":"Jimmy"}' |
51 | 63 | @Post("/person") |
52 | 64 | Person postPerson(Person body) { |
53 | 65 | return new Person(42, "Returning " + body.name()); |
@@ -80,18 +92,29 @@ String addMultiple(List<Person> newGuys) { |
80 | 92 | return "New Guys Added"; |
81 | 93 | } |
82 | 94 |
|
83 | | - // curl -X POST http://localhost:8081/form -H "Content-Type: application/x-www-form-urlencoded" -d "name=Jimmy&email=jim@foo&url=notaurl" |
| 95 | + @Put("person/int") |
| 96 | + int testIntReturn() { |
| 97 | + return 422; |
| 98 | + } |
| 99 | + |
| 100 | + @Put("person/long") |
| 101 | + long testLongReturn() { |
| 102 | + return 69; |
| 103 | + } |
| 104 | + |
| 105 | + // curl -X POST http://localhost:8081/form -H "Content-Type: application/x-www-form-urlencoded" -d |
| 106 | + // "name=Jimmy&email=jim@foo&url=notaurl" |
84 | 107 | @Form |
85 | 108 | @Post("form") |
86 | 109 | String form(String name, String email, String url) { |
87 | 110 | return name + "-" + email + "-" + url; |
88 | 111 | } |
89 | 112 |
|
90 | | - // curl -X POST http://localhost:8081/formBean -H "Content-Type: application/x-www-form-urlencoded" -d "name=FormBeanJimmy&email=jim@foo&url=notaurl" |
| 113 | + // curl -X POST http://localhost:8081/formBean -H "Content-Type: |
| 114 | + // application/x-www-form-urlencoded" -d "name=FormBeanJimmy&email=jim@foo&url=notaurl" |
91 | 115 | @Form |
92 | 116 | @Post("formBean") |
93 | 117 | String formBean(MyForm form) { |
94 | 118 | return form.name + "-" + form.email + "-" + form.url; |
95 | 119 | } |
96 | | - |
97 | 120 | } |
0 commit comments