0.0
No commit activity in last 3 years
No release in over 3 years
Simple Rack Middleware for API Mock
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.9
~> 10.0
~> 3.2

Runtime

~> 1.6
 Project Readme

Rack::APIMock

Simple Rack Middleware for API Mock.

The origin of an idea is https://github.com/CyberAgent/node-easymock

Usage

$ rackup sample/config.ru

Differentiating GET/POST/PUT/DELETE

If you want to use advanced serving features like GET/POST/PUT/DELETE or templates, provide files like in the example below:

GET / (Content-Type: application/json) => index_get.json
GET / (Content-Type: application/xml) => index_get.xml
GET /items/1 => items/1_get.json.erb
POST /items/1 => items/1_post.json.erb
...

Response Headers

<% @status = 200 %>
<% @headers = { "Content-Type" => "application/json" } %>

Query String

template file is items/sample_post.json.erb

<% @status = 201 %>
<% @headers = { "Content-Type" => "application/json" } %>
{
  "method" : "post",
  "status" : <%= @status %>
}

request & response

$ curl -H 'Content-Type: application/json' -X POST http://localhost:9292/items/sample?method
{"method":"post"}

Contributing

  1. Fork it ( https://github.com/[my-github-username]/rack-apimock/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request