Topic
4 replies Latest Post - ‏2012-11-28T03:41:22Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts
ACCEPTED ANSWER

Pinned topic Externally invoking a Worklight HTTP adapter using an HTTP POST

‏2012-11-21T19:05:15Z |
Hello,

Is it possible to invoke a Worklight HTTP adapter externally using an HTTP Post request? As far as I know, I can only invoke an adapter externally using an HTTP Get while appending the adapter function's parameters to the URL. I have a large dynamic payload which needs to be sent and encoding it as a URL parameter doesn't seem feasible.

Any thoughts?
Regards,

Costa
  • AntonAleksandrov
    AntonAleksandrov
    55 Posts
    ACCEPTED ANSWER

    Re: Externally invoking a Worklight HTTP adapter using an HTTP POST

    ‏2012-11-26T08:14:56Z  in response to SystemAdmin
    Hello,

    Yes, you can invoke adapter procedure externally by calling http://server:port/contextpath/invoke API.
    With either POST or GET parameters:
    adapter=adapter-name&procedure=procedure-name&parameters=1,2,3,4

    Depending on WL version you have you might need to specify securityTest="wl_unprotected" on adapter procedure declaration (XML file).
    • SystemAdmin
      SystemAdmin
      2327 Posts
      ACCEPTED ANSWER

      Re: Externally invoking a Worklight HTTP adapter using an HTTP POST

      ‏2012-11-26T08:32:54Z  in response to AntonAleksandrov
      @AntonAleksandrov-->

      This is my simple adapter can u frame the link. so it will be easy for understand. this is my login function. i wrote service for this. now i want to call this adapter external with passing paramter.

      domain : localhost
      port : 8080
      adaptername:student

      function login(studenid,pass){

      var input = {
      method : 'post',
      returnedContentType : 'json',
      path : "University/studentlogin",
      parameters : {
      studenid:studenid,
      pass:pass
      }
      };
      return WL.Server.invokeHttp(input);
      }
      • SystemAdmin
        SystemAdmin
        2327 Posts
        ACCEPTED ANSWER

        Re: Externally invoking a Worklight HTTP adapter using an HTTP POST

        ‏2012-11-27T15:43:18Z  in response to SystemAdmin
        I believe the link would be something like:

        
        http:
        //localhost:8080/invoke?adapter=student&procedure=login&parameters=["myId", "myPassword"]
        


        for GET.
        • SystemAdmin
          SystemAdmin
          2327 Posts
          ACCEPTED ANSWER

          Re: Externally invoking a Worklight HTTP adapter using an HTTP POST

          ‏2012-11-28T03:41:22Z  in response to SystemAdmin
          for Method : Post