Overview Of Endpoints Code - Defining Endpoint functions

Imports
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.api.server.spi.config.Named;
Identify that this file contains endpoints functions
@Api(name = "helloworldendpoints", version = "v1",
            scopes = {Constants.EMAIL_SCOPE },
            clientIds = {Constants.WEB_CLIENT_ID, Constants.API_EXPLORER_CLIENT_ID },
            description = "API for hello world endpoints.")
ClientIds identify which clients are allowed to use these endpoint functions
To allow the API Explorer to use the endpoint functions, include Constant.API_EXPLORER_CLIENT_ID in the list of ClientIds:
import com.google.api.server.spi.Constant;

Constant.API_EXPLORER_CLIENT_ID;
Identifying methods as Endpoint Functions
When a file is marked with the @Api annotation, then by default all methods defined in the file are exposed as endpoint functions. However, you can specify the name, path and method (such as GET or POST) for each method.
For example:
    @ApiMethod(name = "sayHello", path = "sayHello", httpMethod = HttpMethod.GET)
For the full list of @Api annotations, see the Developer's Guide https://developers.google.com/appengine/docs/java/endpoints/annotations

Share this

Related Posts

Latest
Previous
Next Post »