Server API Request METHOD



  • How can we send requests using Server API with (PUT , DELETE.......) methods?



  • @sakorada - read the documentation its in there...



  • @Lindon I can find only callWithGET and callWithPost ,no other Method
    https://docs.hise.audio/scripting/scripting-api/server/index.html#callwithget



  • @sakorada That's all we have. If you want more complicated functionality you need to implement that server side and trigger it with the post/get requests.



  • @sakorada said in Server API Request METHOD:

    @Lindon I can find only callWithGET and callWithPost ,no other Method
    https://docs.hise.audio/scripting/scripting-api/server/index.html#callwithget

    Normally, All of the included methods are enough. Even if you want to delete something, you'll need to use callWithPOST. And you need to arrange the endpoint link in your server for the delete process that used with callWithPOST.

    Why do you need Put / Delete stuff?

    Which system are you using on your server or hosting? Wordpress / Woocommerce?



  • @orange I used callWithGet and callWithPost just fine with my current PHP API (From My Website), but I'm going to move to Serverless (AWS ...Lambda Function and stuff).
    and I just wondering if we had implemented (PUT, DELETE....) so I don't have to make requests with POST for everything.
    But yes, maybe I have to stick to POST then...



  • One more thing I noticed: Server API request data is not JSON format.
    I tried to do

    Server.setHttpHeader("content-type: application/json");
    

    and still doesn't work.

    var data = {
                "name": "Iron Man",
                "status": "Gone gone"
               };
       
        
    Server.setBaseURL("https://postman-echo.com/post");    
    Server.callWithPOST("/", data, function(status, response) {
            Console.print(status);
            if (status == Server.StatusOK) {
                 payload = response;
                Console.print(JSON.stringify(response));
            }
        });
    
    //echo back from server------------------------------------------------------------------------
    {
      "args": {
      },
      "data": "name=Iron%20Man&status=Gone%20gone",
      "files": {
      },
      "form": {
      },
      "headers": {
        "x-forwarded-proto": "https",
        "x-forwarded-port": "443",
        "host": "postman-echo.com",
        "x-amzn-trace-id": "Root=1-60f17642-6b42c7eb593222a77e103b8c",
        "content-length": "34",
        "accept": "*/*",
        "content-type": "application/json",
        "user-agent": "juce",
        "cache-control": "no-cache"
      },
      "json": null,
      "url": "https://postman-echo.com/post/"
    }
    
    var data = {
                "name": "Iron Man",
                "status": "Gone gone"
               };
       
        
    Server.setBaseURL("https://postman-echo.com/post");
        //Try to Set content-type to application/json
    Server.setHttpHeader("content-type: application/json");
        
    Server.callWithPOST("/", data, function(status, response) {
            Console.print(status);
            if (status == Server.StatusOK) {
                 payload = response;
                Console.print(JSON.stringify(response));
            }
        });
    
    //echo back from server------------------------------------------------------------------------
    {
      "args": {
      },
      "data": "name=Iron%20Man&status=Gone%20gone",
      "files": {
      },
      "form": {
      },
      "headers": {
        "x-forwarded-proto": "https",
        "x-forwarded-port": "443",
        "host": "postman-echo.com",
        "x-amzn-trace-id": "Root=1-60f176e9-3369eaac39072e93338cd563",
        "content-length": "34",
        "accept": "*/*",
        "content-type": "application/json",
        "user-agent": "juce",
        "cache-control": "no-cache"
      },
      "json": null,
      "url": "https://postman-echo.com/post/"
    }
    

Log in to reply
 

21
Online

1.6k
Users

4.6k
Topics

42.7k
Posts