EzyHTTP Request Arguments
Updated at 1699803883000EzyHTTP provides a list of aguments to help you handle a request:
| # | Argument | Annotation | Description |
| 1 | Path variable | @PathVariable | Maps a path variable to a java parameter |
| 2 | Request argument | @RequestArgument | Maps a request argument to a java parameter |
| 3 | Request body | @RequestBody | Maps a request body to a java parameter |
| 4 | Request cookie | @RequestCookie | Maps a request cookie to a java parameter |
| 5 | Request header | RequestHeader | Maps a request header to a java parameter |
| 6 | Request parameter | RequestParam | Maps a request prameter to a java parameter |
| 6 | Custom argument | Custom Annotation | Maps a custom argument to a java parameter |
1. Path variable
For example with bellow API, when you call to server
http://localhost:8080/api/v1/author/1, EzyHTTP will map set authorId = 1.@Api @Controller("/api/v1/author") public class AuthorController { @DoGet("/{authorId}") public AuthorResponse getAuthor(@PathVariable long authorId) { // implementation } }
2. RequestArgument
Let's say in the interceptor we set the `hello` argument like this:
public boolean preHandle( RequestArguments arguments, Method handler ) throws Exception { arguments.setArgument("hello", "world"); }
then you can get the
hello argument like this:@DoGet("/welcome") public String welcome( @RequestArgument("hello") String hello ) { // implementation }
3. Request Body
In a post or put method, you can pass an request body to server (maybe form, json or anything else) and you can get the body like this:
@DoPost("/book/add") public BookResponse addBook(@RequestBody AddBookRequest request) { // implementation }
4. Request cookie
Let's say client send to server a cookie named `token` and then, use can the cookie like this:
@DoGet("/welcome") public String welcome( @RequestCookie("token") String token, ) { // implementation }
4. Request Header
Let's say client send to server a header named `token` and then, use can the header like this:
@DoGet("/welcome") public String welcome( @RequestHeader("token") String token, ) { // implementation }
5. Request Parameter
Let's say client send to server a request parameter named `token` and then, use can the parameter like this:
@DoGet("/welcome") public String welcome( @RequestParam("token") String token, ) { // implementation }
6. Custom argument
Let's say we have an inteceptor like this:
@Interceptor public class PermissionIntercepto implements RequestInterceptor { @Override public boolean preHandle(RequestArguments arguments, Method handler) throws Exception { final long userId = authenticationService.verifyAccessToken(accessToken); arguments.setArgument(UserId.class, userId); return true; } }
And then, we can get the userId value like this:
@DoPost("/user/save") public Object userSavePost( @UserId long userId ) { // implementation }
7. Next
You can take a look [list of EzyHTTP's response type](/ezyhttp/guides/ezyhttp-response-types).