I want to run unit tests in my program whenever the api receives a request. the api returns a response once when it has received a valid request, but then later it will send once it's done with the unit tests. The first response is shown in Postman, but not the second repsonse. I can see that it getting send using wireshark though.
These are two separate responses and since this api is what it is, I don't have the power to change it. How can i use Postman to receive the second response as well?
Edit additional information is requested so:
I have in my collection a POST request and when I trigger it I get a response back with a body with:
{
"messageType" : "Response"
"options" : "async"
}
Then the code can see that another response is incoming later, because of the async token.
A bit later another response is received:
{
"messageType" : "Response"
"Tests" : "11 ok tests"
}
But in postman I can't seem to receive the second response, as the transaction is finished after the first one. How can I make postman also receive the second response?
Related
I launched my app on heroku.
And ever since all of my axios get request return a blank html.
axios.post(process.env.REACT_APP_baseServerurl + '/create/get-users')
axios.get(process.env.REACT_APP_baseServerurl + '/create/get-users')
the response i get is always blank.
request
response
but if i change the same request to a post it works fine.
The get request works fine when i try it on my localhost. But when i deploy it on heroku it returns blank.
router.post('/get-users', (req,res) => {
res.json("asdsadas")
})
router.route('/get-users').get((req,res) => {
res.json("yes")
})
the POST request works but GET request returns a 304.
The 304 HTTP Status code means that the resource has not been modified since the last get request. This indicates that the server thinks you already have a copy of up-to-date data. The Server makes this assumption by looking at the If-None-Match and If-Modified-Since in your request header. (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection)
These are the actions you could take:
Cache the data manually on your first successful request (if there is one, otherwise there must be an error in the usage of the If-None-Match and If-Modified-Since headers) and re-use the cached data if the server returns a 304 status code.
Disable the mechanism and live with the fact that you might request the same data the server already gave you.
I see multiple tutorials about Postman/Newman test scripts, however they mostly looks like single requests.
What is the best way to chain Postman test request based on previous results, so eg:
PUT upload request
Test for e.g. status code. If 200, do POST start-processing the just uploaded file, else stop
If 200, then do GET to query
If 200, check JSON against fixed expected JSON output.
Newman seems to run an entire collection independently. I only want to run request 1, which then fires request 2 and request 3 based on output of previous request in that same collection.
You can configure this in the Tests section in Postman by using
if (condition) {
postman.setNextRequest("NAME OF YOUR REQUEST")
}
I'm writing a C# Web API server application, and will send JSON to it via a Mirth HTTP Sender destination. This post is about how to handle error conditions. Specifically, there are three scenarios I want to handle:
Sometimes we take the C# application server offline for a short period for system upgrade or maintenance, and Mirth is unable to connect at all. I want Mirth to queue all messages in order, and when the server is available, process them in the order they were received.
The server receives the request, but rejects it due to a problem with the content of the request, e.g., missing a required field. In accordance with REST conventions, the server will return a 400-level HTTP response. This message would be rejected every time it's submitted, so it should not be re-sent; just log the failure and move on to the next message.
The server receives the request, but something goes wrong on the server, and the server returns an HTTP 500 Server Error response. This would be the appropriate response, for example, when something in the server environment has gone wrong. One real-world example was the time the Web API server was running, but somebody rebooted the database server. REST conventions would suggest we continue to resend the message until the transient problem has been resolved.
For #1, initially I had it queue on failure/always, but it appears the response transformer never runs for messages that were queued (at least, the debug statements never showed in the log). I have turned queueing off, and set it to retry every ten seconds for an hour, and that seems to give the desired behavior. Am I on the right track here, or missing something?
For #2 and #3, returning any HTTP 400 or 500 error invokes the 1-hour retries. What I want is to apply the 1-hour retries for the 500 errors, but not the 400 errors. I’ve tried responseStatus = SENT in the response transformer, but the response transformer only runs once, after the hour has expired, and not for each retry.
This seems like a common problem, yet I’m not finding a solution. How are the rest of you handling this?
You're close!
So by default, the response transformer will only run if there's a response payload to transform. For connection problems, or possibly for 4xx/5xx responses that contain no payload, the response transformer won't execute.
However, if you set your response data types (From the Summary -> Set Data Types dialog, or from the Destinations -> Edit Response, Message Templates tab) to Raw, then the response transformer will execute all the time. The reason being that the Raw data type considers even an empty payload to be "transformable".
So turn queuing back on, and set your response data types to Raw. Then in the response transformer, if you look at the Reference tab there's a category for HTTP Sender:
You'll want the "response status line", that's the "HTTP/1.1 200 OK" line of the response that contains the response code. Here's a response transformer script that forces 4xx responses to error:
if (responseStatus == QUEUED) {
var statusLine = $('responseStatusLine');
if (statusLine) {
var parts = statusLine.split(' ');
if (parts.length >= 2) {
var responseCode = parseInt(parts[1], 10);
// Force 4xx responses to error
if (responseCode >= 400 && responseCode < 500) {
responseStatus = ERROR;
responseStatusMessage = statusLine;
}
}
}
}
I try to create integration tests in SoapUI:
There are property myId=1234 in property file.
I send soap request (named myRequest) contains <messageId>${myId}</messageId>
This request is valid, because ${myId} is replaced by 1234. I receive response.
In my groovy script I want show sent request, value of <messageId>:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def request = groovyUtils.getXmlHolder("myRequest#Request");
log.info(request["//messageId"]);
output: ${myId}
Expected output: 1234
Do you have any idea?
It is possible achieve this without using an additional Groovy Script test step by using Script Assertion for the same request step.
Use below Script Assertion to show the request along with values being replace or the actual request being sent to the server.
//Check if you have got the response
assert context.response, "Response is null or empty"
//show the actual request is being sent
log.info context.rawRequest
I am using RESTClient for firefox addon to test REST API, i set some headers that's working fine if i set request body and method to GET , i couldn't access data via my PHP application, but headers available
**Request headers**
Content-Type : application/json
**Request Body**
[
{
"data1" : "value1",
"data2" : "value2",
"data3" : 1
}
]
How do i set Request body correctly?
Set a body to GET requests is a "nonsense" because GET means retrieve some information and the body of a request is used to send data.
It is precisely from this point of view that web servers, most of the time, ignore the body of a GET request, which could explain why you can't get your data from your PHP script.
If the purpose of your request is to create or update a resource you should consider using a POST or PUT to be REST.
There is already a topic opened with almost the same question here : HTTP GET with request body