1

I have a Clojure based web application using Angular JS. All the REST APIs are written in Clojure using Compojure and Ring. Now we want to host our application on a AWS Fargate instance which is a Spring Boot application.

I have been looking for a way to use existing rest handler in Spring Boot application but no luck so far.

Is there a way to achieve this or any other suggestion that might help us shift the application?

Steffan Westcott
  • 2,121
  • 1
  • 3
  • 13
Manish
  • 11
  • 3
  • you could make a spring controller with `deftype`, that would call your existing clojure code.. https://clojure.org/reference/datatypes#_java_annotation_support . – leetwinski Apr 21 '21 at 09:06
  • @leetwinski I am sorry, I don't really understand how can we use already written url mappings in clojure from spring controller as controller itself contains all url mappings. When a request will come to spring controller it will look for that particular api in the controller itself, so I am confused how can I redirect all http requests to use the rest handler that's written in clojure. If you could provide a small example through templates, that'd be really helpful. – Manish Apr 21 '21 at 11:04
  • Can you clarify if by "existing rest handler" you mean to include your Compojure/Ring app inside another Spring boot app with that also has its own handlers? If so, depending on the routing logic, you could recreate the mappings in a Spring controller, and use interop to call Clojure from Java, as described in https://clojure.org/reference/java_interop#_calling_clojure_from_java – Denis Fuenzalida Apr 22 '21 at 07:04
  • @DenisFuenzalida Yes, by existing rest handler I mean Compojure/Ring app. We want to skip recreating mappings in a Spring Controller as there are a few hundreds APIs written in that app. So, we are looking for a way to reuse those APIs without rewriting them in a Spring controller. – Manish Apr 22 '21 at 10:52
  • 1
    If all the APIs on the Compojure/ring app are mapped to a few routes (eg. starting with `/api`), I guess one approach can be to configure a WebApplicationInitializer (see https://www.baeldung.com/spring-controllers ) and forward requests to those routes to a Clojure servlet or filter that bridges to the Compojure side. See this answer for details: https://stackoverflow.com/a/2818227/483566 – Denis Fuenzalida Apr 23 '21 at 00:47

0 Answers0