0

I have a design dilemma in deciding the response status code and architecture for a middleware we are designing.

So the Client Calls MiddleWare, And middleware calls the 3rd party service to get car-values for a particular car-reg.

If everything goes right and we get car-value, we are sending the status code as 200.

But what if we did call out to 3rd party, we received 200 from them, but it did not have car-value that we want, shall we pass 200 status code back to the client or give a different status code.

The argument given by my middleware team to give 200, is its not an issue its just no data from 3rd party so status should be 200 and a status field in JSON response to tell, the values could not be found.

Which feels quite wrong, if I am client, If I don't get car values, how can it be 200 for me?

EDIT: It's a get request where I pass Car Reg in URL params, I want car value, so anything other than car value is kinda error or failed request for me?

  • According to [Mozilla](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status), a `400` means "*[the] server could not understand the request due to invalid syntax*". If you are getting a `200` back from the third party, then a `400` from your middleware seems wrong to me. – David Arno Jun 26 '19 at 09:11
  • @DavidArno Should it be 200? or some 4XX or 5XX? – susanoo chidori Jun 26 '19 at 09:13
  • [This question](https://softwareengineering.stackexchange.com/questions/358243/should-no-results-be-an-error-in-a-restful-response) may help answer that with the suggestion of using `204` (no content). I personally would go for `200`. But there's no right answer to this. – David Arno Jun 26 '19 at 09:16
  • 1
    @DavidArno `204` IMO would usually be used in some sorts of PUT operations or stuff alike, when you want to inform the client that it needn't move away from the current page/doesn't need to refresh the current page's content. But yeah, `200` is probably the way to go in this case. – Milan Velebit Jun 26 '19 at 09:27
  • It depends on the request. Is the client asking for a specific value (/car/value/x) or is it asking for the model through a query (/car/values/?q=x)? On the other hand, is your middleware a mere proxy or does it add any logic/business that worth translating the 3rd party response into something more useful or meaningful for the client? – Laiv Jun 26 '19 at 12:07
  • @Laiv It's a get request where I pass Car Reg in URL params, I want car value. – susanoo chidori Jun 26 '19 at 16:49
  • @DavidArno the first version of 400 was invalid syntax. Now it is invalid anything as stated in the specific doc for 400: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 – Esben Skov Pedersen Jun 26 '19 at 17:31
  • 1
    I think the code status is irrelevant if you don't solve first what's the role of the middleware within the system. If the middleware is a mere proxy then do nothing and pass forward the response status got from the 3rd party service alongside with the message. If the middleware implements a sort of business and its meant to decouple clients from the 3rd party service, then transform the response into something that *makes sense for the business*. If the business can not operate without `car-value` then do respond 404 (keep trying). If it can operate without then 200 + empty value is ok. – Laiv Jun 27 '19 at 07:03
  • On the other hand, why clients know about the 3rd party service registries or identifiers? If they are bypassing you should not get rid of they lack of consistency and just act like a proxy. – Laiv Jun 27 '19 at 07:06

2 Answers2

1

200 status code should adhere to the standardization specs. Your request was processed right, it's just that there's no value to be returned. There were no errors encountered along the way, so 4xx/5xx status codes shouldn't be thrown. As far as I know, even none of the funky/unofficial status codes are useful in this case, you might construct your own, but be sure to document it so that other devs know what to expect.

Milan Velebit
  • 507
  • 3
  • 13
0

From client's point of view, middleware is service provider or backend. And hence we should code as if middleware is the data/service provider. Based on this point of view:

When refering to firefox documents for http status code, Status code 204 seems to be most correct in this scenario, as the request is successful (to middleware and onwards), but no data to send back, empty response is there.

  • 4
    Mozilla does not maintain the official registry of HTTP status codes. The [IANA](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) does that. – Eric Stein Jun 26 '19 at 14:37
  • Thanks for pointing me to correct documentation. I am updating the answer. – Aditya Ajmera Jun 26 '19 at 16:15