Forum Discussion

venuj1244's avatar
venuj1244
Contributor
12 years ago

Can anybody provide the code sample to call restAPI's from endpoint

  • xorrkaz's avatar
    12 years ago

    From within an endpoint, we typically use restadmin:

     

    <#assign message = restadmin("/messages/id/${mid}").message />

     

    You can also use rest() if you want.

     

    To call the endpoint, we would do something like this (from within jQuery):

     

    $.ajax({
            type: "GET",
            url: "/company/plugins/custom/company/company/our_endpoint",
            data: ({
                    "mid":"${mid}",
                    "xslt":"json.xsl"
            })

    });

     

    The URL for the endpoint can be found when you're defining it.  We set the output format of all of our endpoints to be XML.  This way, we can transform it using JSON if we need to.