How to send the JSON data in rest web services?

前端 未结 2 626
攒了一身酷
攒了一身酷 2021-01-28 05:37

How to send the JSON data in rest web services? I have a json object which contains product Id,store Id,price,product Unit,quantity values.Here All the values are integ

2条回答
  •  长发绾君心
    2021-01-28 06:01

    Since you have tagged this with the Worklight tag, I'm going to assume you meant to ask how to send json data from a worklight client to an external REST service. In order to do this in Worklight, you need to use a Worklight HTTP adapter. See the documentation here: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v600/04_02_HTTP_adapter_-_Communicating_with_HTTP_back-end_systems.pdf

    After creating the Worklight adapter, you can then send your JSON data from the client like this:

    /**********************************************************************************
    *                           Http Adapter call
    **********************************************************************************/
    function callAdapter(){
    
        var myJSONObject = {
            productId: 123, 
            storeId: 123, 
            price: 342, 
            productUnit: "myUnit",
            quantity: 4
        };
    
        var invocationData = {
                adapter : 'MyHttpAdapter',
                procedure : 'myAdapterProcedure',
                parameters : [myJSONObject]
        };
    
        WL.Client.invokeProcedure(invocationData, {
            onSuccess : success,
            onFailure : failure
        });
    }
    
    function success(response){
        console.log("adapter Success");
        console.log(response);
    }
    
    function failure(response){
        console.log("adapter Failure");
        console.log(response);
    }
    

提交回复
热议问题