Skip to main content
Participant
October 11, 2022
Question

Trying to set up simple api - Having Issues

  • October 11, 2022
  • 1 reply
  • 203 views

I am using the api manager and trying to set up a simple api like this:

 

 

<cfcomponent rest="true" restpath="restapi">
 <cffunction name="sayHello" restpath="sayHello" access="remote" returntype="String" httpmethod="GET">
    <cfset rest = "Hello World">
    <cfreturn rest>
 </cffunction>
</cfcomponent>

 

My questions are:

What do I name this file?

Where do I save the file in my site? Is there a certain path or folder structure needed?

In the API manager Can I name the api anything?

What would the endpoint be?

Under resources what would the resource name be specified as?

 

Right now I have the endpoint as mysite.com/restapi. The resource is a get for sayHello but it is returning an error when I try to test it: 

 

"error": "There was some error while invoking the API.Verify and try again"

Any info is appreciated.

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    December 8, 2022

    Hi @cj5FA8 ,

    Put the API Manager aside for the moment. Get the REST API up and running first.

     

    You could proceed as follows:

     

    1) Create the REST CFC and store it under the web root. 

     

    > What do I name this file?

    > Where do I save the file in my site? Is there a certain path or folder structure needed?

     

    You can give the CFC any name you want. Place it in a directory - by any name - under the webroot. For example, in \wwwroot\myRESTApp\Greeting.cfc 

     

    <!--- Greeting.cfc --->
    <!--- located at \wwwroot\myRESTApp\Greeting.cfc --->
    <cfcomponent rest="true" restpath="myRESTComponent">
     <cffunction name="sayHello" restpath="greetingSent" access="remote" returntype="String" httpmethod="GET">
        <cfset var restMessage = "Hello World!">
        <cfreturn restMessage>
     </cffunction>
    </cfcomponent>

     

    2) Register the REST API in the ColdFusion Administrator

    3) Call the REST API in the browser, using http://localhost:8500/rest/myRESTApp/myRESTComponent/greetingSent/ 

    You should then see: Hello World!