Cloud Endpoint parameter should not be named

后端 未结 4 1122
野的像风
野的像风 2021-01-13 11:29

I want send a HashMap from JS application to my Google App. I created a HashMapContainer class such as in : Cloud Endpoints C

4条回答
  •  温柔的废话
    2021-01-13 12:19

    Google Cloud Enpoints documentation says:

    @Named: This annotation indicates the name of the parameter in the request that gets injected here. A parameter that is not annotated with @Named is injected with the whole request object.

    Basically, as far as I understand, when you add @Named annotation, the parameters will be included at the end of the request URL:

    http://end_point_url?parameter1=xxx¶meter2=yyy
    

    Obviously the parameter types that support @Named annotation are only a few (int, long, String, Boolean and their correspondent arrays, I think), because you can't append a whole hashmap to the request URL!

    On the other hand, if you don't use @Named, the parameter will be included (injected) within the POST data.

    In order to send a parameter within the HTTP body using the Google APIs Client Library for JavaScript, you just have to include that parameter into an object called resource inside the JSON-RPC request, like this:

    var req = gapi.client.myApi.endpoint.myMethod({
        'param1': 'FOO',
        'resource': {
            'param2': {
                'value1':'foofoo',
                'value2':'barbar',
                'value3':'foobar'
            }
        }
    });
    

    The API client will automatically send param1 in the URL and param2 in the POST data...

    This is explained in detail in this section of the Google APIs Client Library for JavaScript documentation.

提交回复
热议问题