Spring Cloud — As a reverse proxy server

Muhammad Ahsan
Aurora Solutions
Published in
2 min readMar 13, 2019

A reverse proxy server is a type of proxy server that retrieves resources on behalf of a client from one or more servers. These resources are then returned to the client, as if they were originated from the proxy server itself.

How is it different from forward proxy?

There is a very little difference between forward and reverse proxy server. Let’s assume we have a client which communicates with a remote server for fetching some data. Forward proxy will sit in front of client, and will make sure that the remote server will never communicate/send response directly to the client. Reverse proxy will sit in front of a remote server, and will make sure that the client will never communicate/ask for data from remote server directly, but will always ask proxy server to do so.

Let’s create a spring boot application which will use spring-cloud to create a minimal proxy server. Open spring initializer to create a new project, and add the following dependencies:

Your pom.xml should have the following dependencies

Next, add the @EnableZuulProxy annotation in your MainApplication.java file. It should look like this

Next, add the zuul configuration in your application.yml/properties file

That’s it. All requests with /doctor/anything in the request path, will be redirected to https://doctor-service-host-url/api/v1/doctor, and all requests with /patient/anything in the request path will be redirected to https://patient-service-host-url/api/v1/patient. The client will always request the proxy server, and will never know from where our proxy server is returning the data. It would feel as if the proxy server itself is returning the requested data. Our simple proxy server using spring cloud is ready to go !!!

--

--

Muhammad Ahsan
Aurora Solutions

Full stack developer with major expertise in Java, Spring Boot, React, React Native, Docker, and Kubernetes