PutsReq lets you record HTTP requests and fake responses like no other tool available
Ruby HTML JavaScript CSS CoffeeScript
Clone or download
Latest commit be17d02 May 12, 2018
Permalink
Failed to load latest commit information.
app Add buttons in the website May 11, 2018
bin Add binstubs Jan 2, 2018
config Use event source instead of pusher (#38) Apr 21, 2018
lib Bump version to 0.0.3 Feb 24, 2017
public Fix warnings Dec 26, 2017
spec Use event source instead of pusher (#38) Apr 21, 2018
vendor/assets Add favico; Use rails-assets Sep 7, 2014
.babelrc React WIP Dec 26, 2017
.codeclimate.yml Enable MOAR CC engines (#39) Apr 21, 2018
.coffeelint.json Add houndci config Jul 26, 2015
.eslintignore Enable MOAR CC engines (#39) Apr 21, 2018
.eslintrc Enable MOAR CC engines (#39) Apr 21, 2018
.gitignore Favor npm for fixing heroku deploy Dec 30, 2017
.jshintrc Add houndci config Jul 26, 2015
.postcssrc.yml React WIP Dec 26, 2017
.prettierrc Use event source instead of pusher (#38) Apr 21, 2018
.reek Enable MOAR CC engines (#39) Apr 21, 2018
.rspec Minor refactor; Adds specs Apr 16, 2014
.rubocop.yml Use event source instead of pusher (#38) Apr 21, 2018
.ruby-version Ruby & Rails upgrade tests passing Dec 26, 2017
.simplecov Let's try to make CC and Travis friends again Dec 31, 2017
.travis.yml Bump Ruby 2.5.0 Mar 30, 2018
Gemfile Add pusher-client back May 11, 2018
Gemfile.lock Add pusher-client back May 11, 2018
LICENSE Fix license Sep 1, 2014
Procfile Use event source instead of pusher (#38) Apr 21, 2018
README.md There's no CONTRIBUTE.md May 11, 2018
Rakefile Use event source instead of pusher (#38) Apr 21, 2018
config.ru [WIP] Rails migration initial commit Apr 27, 2014
package-lock.json Update hoek Apr 28, 2018
package.json Added call to donate after npm install (optional) May 11, 2018
putsreq.gemspec Use event source instead of pusher (#38) Apr 21, 2018

README.md

Build Status Code Climate Test Coverage Backers on Open Collective Sponsors on Open Collective

PutsReq

PutsReq lets you record HTTP requests and simulate responses like no other tool available. Try it now!

Check this post: Play Rock-paper-scissors with Slack and PutsReq for some other examples.

Getting Started

Steps to run PutsReq in development.

Install MongoDB

brew install mongo

mongod

Start PutsReq

cd ~/workspace

git clone git@github.com:phstc/putsreq.git

cd putsreq

bundle install

rails server

open http://localhost:3000

Response Builder

The Response Builder is the place where you can create your responses using JavaScript V8.

Here is the list of request attributes you can access to create your responses:

request

// curl -X POST -H 'X-MyHeader: MyHeaderValue' -d 'name=Pablo' https://putsreq.com/<YOUR-TOKEN>

request.request_method
// => POST

request.body
// => name=Pablo

request.params.name
// => Pablo

request.headers['HTTP_X_MYHEADER']
// => MyHeaderValue

Parsing a JSON request:

// curl -i -X POST -H 'Content-Type: application/json' -d '{"message":"Hello World"}' https://putsreq.com/<YOUR-TOKEN>

var parsedBody = JSON.parse(request.body)

parsedBody.message
// => Hello World

response

response.status = 200 // default value
response.headers = {} // default value
response.body = 'ok' // default value

Returning a JSON response:

response.headers['Content-Type'] = 'application/json'

response.body = { message: 'Hello World' }

forwardTo

If you only want to log your requests, you can use PutsReq as a proxy to forward them.

request.forwardTo = 'http://example.com/api'

You can also modify the requests before forwarding them.

// add or change a header
request.headers['X-MyNewHeader'] = 'MyHeaderValue'

var parsedBody = JSON.parse(request.body)

// add or change a value
parsedBody['my_new_key'] = 'my new value'

request.body = parsedBody

request.forwardTo = 'http://example.com/api'

CLI

Want to test Webhook calls against your localhost? PutsReq makes it easy!

You can think of it, as a kind of ngrok, but instead of creating a tunnel to your localhost, PutsReq polls requests from YOUR-PUTSREQ-TOKEN and forwards to your localhost.

gem install putsreq

putsreq forward --to http://localhost:3000 --token YOUR-TOKEN

Listening requests from YOUR-TOKEN
Forwarding to http://localhost:3000
Press CTRL+c to terminate
2016-12-21 20:49:54 -0200       POST    200

Ajax

PutsReq supports CORS, so you can use it to test your Ajax calls.

<html>
  <head>
    <title>Your Website</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script>
    // Sample PutsReq Response Builder
    // https://putsreq.com/<YOUR-TOKEN>/inspect
    // response.headers['Content-Type'] = 'application/json';
    // response.body = { 'message': 'Hello World' };

    // Sample Ajax call
    $.get('https://putsreq.com/<YOUR-TOKEN>', function(data) {
      alert(data.message);
      // => 'Hello World'
    });
    </script>
  </head>
  <body>
  </body>
</html>

Sample Integration Tests

https://github.com/phstc/putsreq_integration_sample

Production

In production (Heroku), PutsReq runs on mLab sandbox, with a storage of 500 MB. For avoiding getting exceeding the capacity, the requests and responses collections must be converted into capped collections.

db.runCommand({ "convertToCapped": "requests",  size: 15000000 });
db.runCommand({ "convertToCapped": "responses", size: 15000000 });

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

Please see LICENSE for licensing details.