Giter Site home page Giter Site logo

api-mock-server's Introduction

Mock API Server

A Full-Featured API Mock Server

Code Climate Build Status

Demo

Installation

Install Mongodb

Install MongoDB

Clone the Project

git clone [email protected]:zlx/API-mock-server.git

Install Dependancy

bundle install --path=vendor/bundle

Usage

Mongodb Config

Configurate mongodb in mongoid.yml like below:

cp mongoid.yml.example mongoid.yml

Start Server

rackup

Visit

http://localhost:9292/admin

Default username/password: admin/admin

HowTo

How to config admin username/password ?

Config admin_user and admin_password in apimockserver.rb

How to config Top Namespace ?

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

How to redirect your routes to mock server

Add redirect route at the end of your route.rb

constraints(Domain::Mockapi) do
  get "/*any", to: redirect { |p, req| "http://<<your-mockapi-server>>/#{req.fullpath}" }
end

create domain/mockapi.rb file

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

wiki

Test

Mock Data

ruby seed.rb

Test the service using a curl or your favourite tool

curl http://localhost:4000
{ "hello": "world" }

Postman

https://github.com/a85/POSTMan-Chrome-Extension

Deploy on Server

work with unicorn

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"

api-mock-server's People

Contributors

alfredsang avatar zlx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.