Skip to content
akihito edited this page May 11, 2014 · 13 revisions

Install

$ git clone  git@github.com:takihito/Web-API-Mock.git 
$ cpanm ./Web-API-Mock
:
$ run-api-mock --help 
Usage:
        $ run-api-mock --files api.md --not-implemented-urls url.txt --port 8080

Create API Documentation

# api.md 

## GET /hello

+ Response 200 (text/plain)

        Hello World

Start Mock Server

$ run-api-mock --files api.md 
HTTP::Server::PSGI: Accepting connections at http://0:5000

Options

  • files
  • API Document Files.
$ run-api-mock --files api1.md --files api2.md
  • not-implemented-urls
  • Add "501 Not Implemented" info (Method and URL).
GET,/hello/hoge
POST,/hello/foo
  • port

  • server port

  • Other...

  • plackup options

Switch to the Production API

By using nginx

see not-implemented-urls option.

$ run-api-mock --files api.md --not-implemented-urls url.txt --port 5001
upstream mock_backend {
   server 127.0.0.1:5001;
}

upstream prod_backend {
   server 127.0.0.1:5002;
}

server {

: 
: 

    location ~ ^/ {
         proxy_intercept_errors on;
         proxy_pass http://mock_backend;
         proxy_set_header Host $host;
    }

    error_page 501 =200 @prod;
    location @prod {
        proxy_pass http://prod_backend;
        proxy_set_header Host $host;
    }

Clone this wiki locally