Micronaut HTTP Client handeling empty parameters in GET requests

579 views Asked by At

Micronaut declarative HTTP Client question

I need to construct a GET request that looks like this:

URL/index?xxx=42&singledatapoint&Unadjusted

If I use MN’s declarative HTTP Client, like this:

@Get('/index?no={number}&singledatapoint&Unadjusted')
HttpResponse<String> getData(int number)

The final URL looks like this:

URL/index?no=42&singledatapoint=&Unadjusted=

MN has added = (equal signs) to the end of the empty parameters.

This fails with a invalid request on the server.

I tried the following permutations with the same sad results:

URL/index?no=42&singledatapoint=””&Unadjusted=””
URL/index?no=42&singledatapoint=null&Unadjusted=null

My question: How do I force MN to stop putting = (equal sign) after the empty parameters?

Please note: The receiving server (on which I have no control) for the request does not accept the = that is why I need it removed.

Code

@MarketData
@Client('https://someurl')
interface MarketDataClient {

    @Get('/index?no={number}&singledatapoint&Unadjusted')
    HttpResponse<String> getData(int number)

}

@MarketData
@Filter(MATCH_ALL_PATTERN)
class MarketDataFilter implements HttpClientFilter {

    @Override
    Publisher<? extends HttpResponse<?>> doFilter(MutableHttpRequest<?> request, ClientFilterChain chain) {
        //NO WORKY!
        request.parameters.add('singledatapoint', null) //MN ignores the parameter
        request.parameters.add('Unadjusted', '') //gives the '='
        chain.proceed(request)
    }

}

@FilterMatcher
@Documented
@Retention(RUNTIME)
@Target([TYPE, PARAMETER])
@interface MarketData { }
0

There are 0 answers