1

I want to create 2 endpoints in my @RestController annotated spring boot project.

Endpoint 1: api/account/balance/{accountnum}

Endpoint 2: api/account/balance/{accountnum}?datetime={datetime}

Both end points are having same URI until the path variable but second one has an additional query param in it. But when i send request it always go to first endpoint(without query param) eventhoug i send datetime query param in the request.

Is it possible to create these 2 endpoints with same URL but one with additional query param?

0

2 Answers 2

4

No, You can't, what you can do is get the datetime param value, if it has value, then do the operation based on it else do the other operation.

Sign up to request clarification or add additional context in comments.

Comments

0

You can create a single endpoint with Queryparameter as optional by default. If you want to specify you can use like below

@RequestParam(value = "myProp", required = false) String myProp

1 Comment

I think what @Te J as is trying to say is to have one method in the controller to resolve the URI api/account/balance/{accountnum}. Then based on the param datetime; which should be optional, you can return the desired result by the controller. Otherwise it will not be possible to have 2 resolver for the same endpoint unless if one is a post and the other is a get.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.