Going @Named to Google Cloud Endpoints

I don’t understand what @Named is used in Google cloud endpoints. The documentation states:

This annotation indicates the parameter name in the query that is entered here. A parameter that is not annotated using @Named introduces the entire request object .... This example shows the use of @Named:

@ApiMethod( name = "foos.remove", path = "foos/{id}", httpMethod = HttpMethod.DELETE) public void removeFoo(@Named("id") String id){} 

where @Named indicates that only the id parameter is entered into the request.

If @Named was not used in this example, what is “entered” instead? with "full request"? If anything, what exactly is being introduced? And what is the “whole query”? Should the @Named object always be part of the path defined in @Apimethod?

Thanks.

+4
source share
1 answer

EDIT : although my answer below is actually not true, it is not complete at all. Basically, when you add the @Named annotation, the parameters will be included at the end of the request URL:

 http://endpointurl?parameter1=xxx&parameter2=yyy 

If you are not using @Named , the parameter will be included (entered) in the POST data. You can see this very clearly by creating a testing endpoint with some named parameters and some unnamed, and using some query exploration tool like Firebug.

Obviously, the parameter types that support the @Named annotation @Named just a few (int, long, String, Boolean and their corresponding arrays, I think).

What I said in my original answer below is not false, but not a complete answer ...


The original answer . As far as I understand, the purpose of @Named is to specify the parameter name in the request URL. Thus, the parameter may have a name inside your application and another name open at the endpoint.

This is almost the same as @SerializedName in GSON or @Column in JDO. All of these annotations allow you to have 2 different names for your parameters, one in your application, the following Java naming conventions, and another name following other conventions such as URLs or JSON ...

In your example, you may not notice the difference, but you can have this method:

 @ApiMethod( name = "remove", path = "remove", httpMethod = HttpMethod.DELETE) public void removeFoo(@Named("my_app_id") String myAppID){} 

In this case, the parameter name in the URL will be:

 https://mygaeappid.appspot.com/_ah/api/yourapi/v1/remove?my_app_id=1234 

And no, the @Named object does not always have to be part of the path defined in ApiMethod.

+4
source

All Articles