PutsReq lets you record HTTP requests and simulate responses like no other tool available. Try it now!
Steps to run PutsReq in development.
brew install mongo
mongod
cd ~/workspace
git clone [email protected]:phstc/putsreq.git
cd putsreq
bundle install
rails s
open http://localhost:3000
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:
// 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.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' };
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';
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>
https://github.com/phstc/putsreq_integration_sample
Please see LICENSE for licensing details.