Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create REST endpoint in spring boot in runtime?

I'm currently working with Telegram bots and seem like some telegram bots could be served at one endpoint due to lack of information in bot's message to separate one bot's message from another one. New bots can appear during runtime, so I can not hardcode some separate endpoints for every bot. So there is it possible to create a new endpoint by template in spring boot in runtime?

like image 861
sphinks Avatar asked Aug 06 '16 19:08

sphinks


People also ask

Can we create REST API with spring boot?

Advantages of using Spring BootIt allows you to create REST APIs with minimal configurations. A few benefits of using Spring Boot for your REST APIs include: No requirement for complex XML configurations. Embedded Tomcat server to run Spring Boot applications.

Which of the below dependency is needed for implementing a spring REST endpoint?

To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file.

Is spring boot only for REST API?

No Spring Boot isn't just for REST APIs. Spring Boot is "just" a mechanism for autoconfiguring a Spring Framework based application. Therefore you can use and it does get used for all kinds of stuff.


Video Answer


1 Answers

No. The DispatcherServlet is initialized in an ApplicationContext thats a child context of your root context, so you can't access it.

One way to have a "dynamic" endpoint is to use wildcards in the Request mapping.

@RequestMapping(value="/results/**", method=RequestMethod.GET)
public SomeResult handleResults(HttpServletRequest request) {
     String path = request. getRequestURI();
     if("asd".equals(path)){...}
}  
like image 130
Evgeni Dimitrov Avatar answered Oct 31 '22 15:10

Evgeni Dimitrov