3

I need to create a Rest endpoint dynamically in my Spring Boot application. Instead of statically creating the class with @RestController, is there a way to instantiate and activate a Rest service at runtime? It should be possible to specify the endpoint, input parameters etc at runtime.

Are there some Groovy options too?

Thanks, Sandeep Joseph

1 Answer 1

1

I think the approach to take would be to create a custom MvcEndpoint that will handle all requests on a specific path, from there depending on your internal configuration you can process requests. It's basically just a Servlet (that's also an option). You're fully in control of the request.

public class MyEndpoint extends AbstractMvcEndpoint 
// can optionally implements ApplicationContextAware, ServletContextAware
// to inject configuration, etc.
{
    @RequestMapping("/dynamic-enpoints-prefix/**")
    public ModelAndView handle(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
      // here you have the request and response. Can do anything.
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.