-
-
Save shilovk/1de33d09651eb267194d50ba0977da98 to your computer and use it in GitHub Desktop.
Postman pm.sendRequest example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To send a request via the sandbox, you can use pm.sendRequest. | |
| ``` | |
| pm.sendRequest('https://postman-echo.com/get', function (err, res) { | |
| pm.expect(err).to.not.be.ok; | |
| pm.expect(res).to.have.property('code', 200); | |
| pm.expect(res).to.have.property('status', 'OK'); | |
| }); | |
| ``` | |
| Without additional options, this will sent a GET request to the URL specified. | |
| If you prefer to be more explicit, you can use the complete syntax: | |
| ``` | |
| pm.sendRequest({ | |
| url: 'https://postman-echo.com/post', | |
| method: 'POST', | |
| header: 'headername1:value1', | |
| body: { | |
| mode: 'raw', | |
| raw: JSON.stringify({ key: "this is json" }) | |
| } | |
| }, function (err, res) { | |
| console.log(res); | |
| }); | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment