Skip to content

PutsReq lets you record HTTP requests and simulate responses like no other tool available

Notifications You must be signed in to change notification settings

WesKetch/putsreq

 
 

Repository files navigation

Build Status

PutsReq

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

Getting Started

Steps to run PutsReq in development.

Install MongoDB

brew install mongo

mongod

Start PutsReq

cd ~/workspace

git clone [email protected]:phstc/putsreq.git

cd putsreq

bundle install

rails s

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 variables 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

Sample 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

Sample 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 forward 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';

last_request & last_response

The last received request and response are also available in the Response Builder context through the variables last_request and last_response.

Ajax

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

// Sample PutsReq Response Builder
// https://putsreq.herokuapp.com/<YOUR-TOKEN>/inspect
// response.headers['Content-Type'] = 'application/json';
// response.body = { 'message': 'Hello World' };

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

Sample Integration Tests

https://github.com/phstc/putsreq_integration_sample

About

PutsReq lets you record HTTP requests and simulate responses like no other tool available

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 73.2%
  • CSS 21.2%
  • CoffeeScript 3.4%
  • JavaScript 2.2%