EzyHTTP Request Arguments

Updated at 1699803883000
EzyHTTP provides a list of aguments to help you handle a request:

ArgumentAnnotationDescription
1Path variable@PathVariableMaps a path variable to a java parameter
2Request argument@RequestArgumentMaps a request argument to a java parameter
3Request body@RequestBodyMaps a request body to a java parameter
4Request cookie@RequestCookieMaps a request cookie to a java parameter
5Request headerRequestHeaderMaps a request header to a java parameter
6Request parameterRequestParamMaps a request prameter to a java parameter
6Custom argumentCustom AnnotationMaps 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.