This example illustrates how a REST API can be called with the help of Postman.
This guide is going to illustrate how API engineering and testing can be done using the API development environment Postman.
You can download Postman from here: https://www.getpostman.com/apps
The only task in this little example is to call the following Echo-Endpoint with the help of Postman:
URL: https://www.putsreq.com/tGemy9dwjunY1e19JcLt
Method: POST
Sample Request • Header: Content-Type: application/json • Body:
{
"variableA": "Data A",
"variableB": "Data B",
"businessKey": "case-001"
}• Optional: businessKey
Success Response • Code: 200 OK • Sample Body:
{
"variableA": "Data A ECHO!!!",
"variableB": "Data B ECHO!!!",
"businessKey": "case-001"
}Error Response • Code: 404 NOT FOUND
Try to figure out how this information can be used to call the
Echo-Endpointin Postman.
This is optional: Just in case the predefined endpoint is not working or may want to create an own instantiation.
You may create an own version of the Echo-Endpoint on PutsReq using the following script:
if (request.headers['CONTENT-TYPE']!='application/json') {
response.status = 404;
response.headers = {};
response.body = 'no JSON body';
} else {
parsedBody = JSON.parse(request.body);
if (parsedBody.variableA && parsedBody.variableB) {
response.status = 200;
response.headers['Content-Type'] = 'application/json';
response.body = {
variableA: parsedBody.variableA + " ECHO!!!",
variableB: parsedBody.variableB + " ECHO!!!",
businessKey: parsedBody.businessKey // optional
};
} else {
response.status = 404;
response.headers = {};
response.body = 'not found';
}
}