Question

I am trying to implement a mock REST service that will recieve a request from a client and then pass on this request to the real REST server and then take that response and send back a cut down version to the client. I would like to run this on linux if at all possible but any programming language will do but preferably ruby / python if possible

So basically:

http Get mock:8080/all/fruit/ ->-> (My mock/proxy REST) ->-> http Get real:8080/all/fruit
returns(apple0 <-<- (My mock/proxy REST)<-<- returns( apple,orange,bananna)

I have looked at a few solution online but cannot seem to find one that mentions this and was wondering does anyone have any ideas?

Was it helpful?

Solution

You could hack something together with Ruby Sinatra pretty painlessly. This will take the path of the request, use curl to get the response from the real server, and pass it back to the requesting client. If you're trying to match content types to something other than text html, you'll need a little bit more handling for that. The backticks will give you as a text string the output from the system command.

require 'sinatra'

REAL_SERVER = "host:port"

def my_processing(input_data)
  # do stuff
end

get '/*' do |path|
  real_return = `curl #{REAL_SERVER}/#{path}`
  my_processing(real_return)
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top