3

Advanced REST client is a great test tool for developing a REST server. Without this, I had to make a request using curl in command line. curl is not hard to use. But Advanced REST client is not only super easy to use but full-featured. Moreover I do not need to develop a client to test it.

The problem was developing client while server was also in progress. I could not find the test method. I wrote this code to capture all requests using flask. This program returns necessary information with Content-Type: application/json.

from flask import Flask, request, jsonify
app = Flask(__name__)

@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT', 'DELETE'])
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def echo(path):
    return jsonify(headers=str(request.headers),
                   args=request.args,
                   form=request.form,
                   method=request.method,
                   path=request.path,
                   url=request.url)

if __name__ == '__main__':
    app.run(debug=True)

My question is: Is there a server version analogous to Advanced REST client?

Note that: This question is transferred from SO and Web Applications.

1 Answer 1

2

Essentially, you want something that will mock the server response for you. Which mocking method depends on what you're using to develop your client. I've used Mockito for Java client development. There is a Mockito for Python but I've not used it. From the documentation it looks like it provides the same feature set that the Java version does.

Mockito lets you replace an object with a mock object that only returns what you tell it to. So for example, you could temporarily replace your call to jsonify with a mock method that will return a json string containing some test data instead of trying to communicate with the server that isn't there.

Also, questions about code mocking are absolutely on topic at SO.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.