Forum Discussion

EquatorDevelopr's avatar
11 years ago

Call Endpoint from Custom Component

Hi,

 

I want to get results from an endpoint in my component without using JS, is there any way to achieve this?

 

In endpoint I use http.client to query external web API and I want to be able to get results in custom component.

  • EquatorDevelopr - I don't think there is any other way of doing this, you can call an endpoint via ajax call from your custom component. About endpoints

     

    You can use the following code:

     

    <#assign your_endpoint_url = "/plugins/custom/community_name/community_name/your_endpoint" />
    
    <@liaAddScript>
    (function($) {
            $(document).ready(function() {
    			$.get( "${your_endpoint_url}" ).done(function( data ) {
    						//your code goes here
                        }).fail(function() {
    						//something
    					})     
    		});
    })(LITHIUM.jQuery);
    </@liaAddScript>

     

    Other threads

  • EquatorDevelopr - I don't think there is any other way of doing this, you can call an endpoint via ajax call from your custom component. About endpoints

     

    You can use the following code:

     

    <#assign your_endpoint_url = "/plugins/custom/community_name/community_name/your_endpoint" />
    
    <@liaAddScript>
    (function($) {
            $(document).ready(function() {
    			$.get( "${your_endpoint_url}" ).done(function( data ) {
    						//your code goes here
                        }).fail(function() {
    						//something
    					})     
    		});
    })(LITHIUM.jQuery);
    </@liaAddScript>

     

    Other threads

  • NicoB's avatar
    NicoB
    Lithium Alumni (Retired)

    Hi EquatorDevelopr 

    http.client is not available in custom components (one of the reason being that community performance could be affected by an external resource) so the only option, as VarunGrazitti was suggesting, is to invoke the endpoint through an Ajax call.

    If this is a show stopper requirement then you might want to get in touch with Lithium's Professional Services team to try and scope up a possible solution to this problem.

     

    Thanks,

     

    Nico