Summary
I am developing a server to be like a sort of a proxy in Clojure, with pedestal service + lein as a base:
- Receive requests
- Forward requests to external servers
- Make multiple requests server-to-server to feed a bigger json and return as a single request to the client
It's easy to code and there are many resources on how to serve a route,
however I could not find any easy way, how to have a Clojure pedestal rest
service together with forwarding routes
Example
- Client calls [GET] /billing => proxy-clojure-server
- proxy-clojure-server authenticate request with client credentials => auth-server
- proxy-clojure-server fills json with billing data => billing-server
- proxy-clojure-server fills json with customer data => customer-server
- proxy-clojure-server returns 200 with complete JSON resolved
Setup
- I have a project with a similar structure as doing: lein new pedestal-service my-app
What I've been trying
- I have been trying to use something like https://github.com/tailrecursion/ring-proxy
Example:
(ns your-ns
(:require [tailrecursion.ring-proxy :refer [wrap-proxy]]))
(def app
(-> routes
(wrap-proxy "/remote" "http://some.remote.server/remote")))
I am just not able to mix routing system from pedestal with this proxy solution, routes are different, seems like, maybe I will need to do it with a different approach
Disclaimer
- I know basic forwarding can be done by nginx, varnish, any other load balancer also. But my idea here is to fill up data from different servers making it simplified for the client
- I am a newbie with Clojure, as you may have noticed. And I ran out of options, because google about that is also complicated, sometimes useless