I have developed an API that needs to return a 204 - No Content Response
import { Controller, Get, Header, HttpStatus, Req, Res } from '@nestjs/common';
import { Response } from 'express';
@Get("mediation-get-api")
@Header('Access-Control-Allow-Origin', "*")
@Header("X-Frame-Options", "SAMEORIGIN always")
async getMediationAPI(@Req() _request,
@Res() _res) {
let APIResponse: any
APIResponse = await this.ServiceObj.getResult(_request)
console.log("APIResponse point")
console.log(APIResponse)
if (APIResponse != undefined) {
console.log("Not Empty Response")
_res.json(APIResponse.data).status(HttpStatus.OK)
_res.statusCode = HttpStatus.OK
_res.statusMessage = APIResponse.statusText
} else {
console.log("Empty Response")
_res.json({}).status(HttpStatus.NO_CONTENT)
_res.statusCode = HttpStatus.NO_CONTENT
// _res.statusMessage = "No Content"
}
console.log("Response")
console.log(_res)
return _res
}
Even after specifying the HttpStatus, the API response is still showing as 200 OK
I attempted to set the status code in the Headers but there was no change