Using tag vs script syntax for rest api

Hi everyone…thanks for any insights.

I am trying to us tag syntax for a rest api, and I am coming to the conclusion it won’t work. I can create the mappings in lucre web admin, and if I run the following code (using cfscript):

component restpath="/system" rest="true" {
	remote struct function getOS() httpmethod="GET" restpath="os" {
	return server.os;
        }
}

I get this returned:

{“version”:“10.16”,“buildnumber”:"",“additionalinformation”:"",“archModel”:64,“hostname”:“Macbook-Air”,“name”:“Mac OS X”,“macAddress”:"##-##-##-##-##-##",“arch”:“x86_64”}

If I try a tag based approach, code below:

<cfcomponent rest="true" restpath="/system" >
!---test function---
   <cffunction name = "getOS" returntype="struct" restpath="os" access="remote" httpmethod="GET">
           <cfset var response = server.os>
           <cfreturn response>
  </cffunction>
</cfcomponent>

I get the following:

“no rest service for [/system/os] found in mapping [/test]”

Note, I had to remove the “<” in the code above to post here. Why does the tag syntax not work? Thanks.

Hi @Doug_Hyde, I’ve checked your above test codes. Both tag and script syntax works fine for me. But if I did any changes in restPath means, it had needed to restart lucee to work with the new restPath. Did you try that with restarting lucee?

FYI, you can use the preformatted text field to include the codes in a post and also I edited your details in the post to show the code.

1 Like

what is /test mapped to?

are both the script and tag components in the same directory?
If they are, they will need different restpath

I put one cfc in the directory, then the other. I now have the two files in the same directory, one with restpath = “system” and the other with rest path = “system2”. I tried restarting as suggested by cfmitrah and that seemed to work - I have the tag based version working now. Thanks to you both. Curious though that one has to restart for tag-based, and not for the script.

while changing the restPath in either tag-based or script syntax, it has needed a restart lucee to work.

1 Like

What I’ve also done in the past is: instead of restarting Lucee, I just run the restinitapplication() from within a simple .cfm template (e.g. called initRest.cfm) in the same web context. Then calling that template should refresh everything quickly during development.

1 Like

Thanks. Good idea. I have done that

1 Like