A Full-Featured API Mock Server
git clone [email protected]:zlx/API-mock-server.git
bundle install --path=vendor/bundle
Configurate mongodb in mongoid.yml like below:
cp mongoid.yml.example mongoid.yml
rackup
http://localhost:9292/admin
Default username/password: admin/admin
Config admin_user and admin_password in apimockserver.rb
Top Namespace is used for specific api version.
for an example, if you config top_namespace = "/api/v1"
, then you must visit "/api/v1/me" to reach "/me" route which you created.
Top namespace is a global setting, so it will take an effect for every routes you created.
To config top_namespace in in apimockserver.rb
constraints(Domain::Mockapi) do
get "/*any", to: redirect { |p, req| "http://<<your-mockapi-server>>/#{req.fullpath}" }
end
module Domain
APIs = %w{
}
class Mockapi
def self.matches? request
api = request.fullpath.sub(/\?.*/, "")
api.in? APIs
end
end
end
Assign your mock apis in APIs
ruby seed.rb
curl http://localhost:4000
{ "hello": "world" }
Guide for setup unicorn for rack app
Below is an simple example for unicorn configure:wiki
# set path to app that will be used to configure unicorn,
# note the trailing slash in this example
@dir = "/home/deploy/rails_apps/API-mock-server/"
worker_processes 2
working_directory @dir
timeout 30
# Specify path to socket unicorn listens to,
# we will use this in our nginx.conf later
listen "#{@dir}tmp/sockets/unicorn.sock", :backlog => 64
# Set process id path
pid "#{@dir}tmp/pids/unicorn.pid"
# Set log file paths
stderr_path "#{@dir}log/unicorn.stderr.log"
stdout_path "#{@dir}log/unicorn.stdout.log"