How to Simulate a 404 Not Found Response

I have to ask this question because when I search for this topic, I just find people complaining about 404s they have been getting.

Essentially I have the endpoint: {{baseUrl}}/classes/:class_id/assessments/term/:term_id/grades, and I have created some responses for different values of the path variables. However, if I make a request to this endpoint using values for the path variables that I haven’t created a response for, Postman isn’t sending back a 404. Instead it is just picking one of the existing responses to send back, and reporting it as a Success on the mock server.

So I created another response and chose 404 Not Found for the status code. I left the path variables blank, then tried *, but still the problem persisted.

Could someone please help me create a proper 404 response for when the values of the path variables are unrecognised? Thank you!

Hey @chris12dec :wave:

Welcome to the Postman Community! :postman:

I need to have a think about this and experiment a bit to see what can be down here. Seems like the mock server is not finding a match and then just returning first example (or one you have created) as the response. I’m not 100% sure but I don’t think that there is a default or a fallback example.

You can try and do something thing with the x-mock-response-name header and forcibly direct it to that 404 example under a given condition. That seems like some you don’t want to do though. You could also use x-mock-response-code header to direct the request to an example with a 404 code.

I’ll try somethings out and see if I can get a basic working solution for you or maybe in the meantime someone else might have different thoughts around this.

Hi Danny, Thanks a lot. I have just been told that for the project I am working on, I won’t need to worry about the possibility of sending requests with unknown parameters, so you could probably put this on the back burner for now. Thanks.

No worries. :+1:

I would counter that and suggest that it’s a great exploratory testing technique to check those assumptions, investigate what the behaviour of those endpoints are when unexpected data is supplied :smiley:

That could be with a mock server or more importantly against the real implementation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.