• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Trying to set up simple api - Having Issues

New Here ,
Oct 11, 2022 Oct 11, 2022

Copy link to clipboard

Copied

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.

Views

121

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 08, 2022 Dec 08, 2022

Copy link to clipboard

Copied

LATEST

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

BKBK_0-1670506342705.png

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

You should then see: Hello World!

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation