2

I have tried one undefined rest path through ColdFusion Rest Playground and it gives response like below;

{
    "MESSAGE": "Not Found",
    "STATUS": 404
}

When I am trying the same from POSTMAN, its gives 404 server error!

server error 404 - File or directory was not found. The resource you are looking for may have been removed, renamed, or temporarily unavailable.

Tried using Accept header as application/json, but its not working.

Here is the configuration of REST Service;

Root Path                           Service Mapping     Default     Host:Port
D:\Projects\restSample\             v1                  NO          my.restAPI

REST Path
rest

And the URL I have tried;

http://my.restAPI/rest/v1/api/test => Working
http://my.restAPI/rest/v1/api/test1 => Gives 404 (but not JSON)

api.cfc

<cfcomponent rest="true" restpath="api">
     <cffunction name="getTest" restpath="test" access="remote" returntype="struct" httpmethod="GET" produces="application/json">
         <cfset var response = {} />
         <cfset response["message"] = "Test" />
         <cfreturn response>
     </cffunction>
</cfcomponent>

How can I get the response as JSON format in POSTMAN for http://my.restAPI/rest/v1/api/test1?

Justin
  • 378
  • 1
  • 3
  • 12

1 Answers1

0

You need to define your Error model class consisting of details such as Error code, message, HTTP status codes or any additional information you want to return during the course of an exception or to be specific [Resource not found].

In case of http://my.restAPI/rest/v1/api/test1

Assuming, test1 is a resource (you are requesting or creating) which doesn't exist.

The response should be your Error model filled up with all information, as part of exception handling or code validation!

Harsh
  • 812
  • 1
  • 10
  • 23