How to record http requests to be used in Postman
This is my second blog in the blog series around Postman.
You can find the others here:
- Using Postman for Odata development
- Using environment and variables in Postman [Since DJ Adams have already covered environment and variables in this blog. I won’t repeat his.]
- How to record http requests to be used in Postman
- Using Postman collections in your CI
In this blog I will show you a few tricks to speed of the task of capturing the requests to the backend.
It’s a bit of a pain to manually capture the requests from the debugger and copy them into Postman, Wouldn’t it be cool if we could use like a macro recorder for it?
Well you are in luck, of course we can do that.
It seem’s like for the current native Postman app you can only capture HTTP requests and not HTTPs. See bug referenced here
Luckily there is another way which probably is needed for most of us since we are often behind a company proxy.
You need to install the Postman Intercepter and the Postman Chrome extension
Now while it will say that it is deprecated, it’s pretty useful together with the interceptor to record requests.
Now as soon as you install the interceptor you can set a filter on what requests you want to intercept. I’ve set mine to .*/sap/opu/odata
So it is only odata requests that i’m capturing.
Now in the Chrome extension version of Postman click the interceptor button in the top right corner
Now all requets made in the browser that fits your filter will be shows in the history of the extension. IF you are really need, then register and sign in on both versions of postman. This way you will automatically get the requests directly in the native postman app.
Now let’s take it for a spin. I’ve created a very simple CRUD application based on the GWSAMPLE_BASIC odata service in ES5. You need to create a destination for the ES5 system and then you can close the repository if you want to. I won’t go into details about how to do that in this blog.
But when I run that application from webide, I already see the requests popping into my history
However they are all recorded as POST batch request. Which makes it a bit tedious for us to distinguish and target test the APIs.
So open the Chrome debugger and go to sources. Navigate to the component.js file and set a breakpoint in the line this.getRouter().initialize(). What we are intending to do here is to disable batch processing.
Now clear your history in postman and hit refresh. When you reach your breakpoint open the console and add the following “this.getModel().setUseBatch(false)” and hit enter.
This way you are disabling batch processing for that particular model. If you have other named models in your app. Do the same for them.
Now when you inspect postman again, you will see everything recorded as individual requests.
Now you can save all the requests to a collection and start editing them by giving them appropriate names and maybe add variables in as described by DJ Adams in his blog.
Also if you are using environments which I urge you to do, then change the URL, so you can run the same request set on numerous systems.
Now you can test your collection by pressing the run button as shown in my previous blog. This is also a great way of creating testdata 😉
Seems like this is your 3rd blog post, not second as stated in first paragraph, but yes, thank you for sharing. Looks great! 🙂
Thanks Jakob for the great blog, interceptor is a must have!
Unless you aren't behind a proxy. Then you can use the native and record them there ?