访问Hello-World Google Cloud Endpoint服务的URL是什么?

时间:2022-03-31 20:20:09

I've generated a Google Endpoint AppEngine project in Eclipse by using the Generate AppEngine BackEnd as described in this blog post. What that post does not describe however, and which the official Google Docs describe poorly as well, is which URL I can access that service with locally?

我已经使用Generate AppEngine BackEnd在Eclipse中生成了一个Google Endpoint AppEngine项目,如本博文中所述。然而,该帖子没有描述的内容,以及官方Google Docs描述不佳的内容,我可以使用本地访问该服务的URL?

The service generated has one generated endpoint called DeviceInfoEndpoint. The code is shown below as well as the code in web.xml. Which URL should I access listDeviceInfo() with given that I'm hosting on port 8888 locally? I've tried the following:

生成的服务有一个名为DeviceInfoEndpoint的生成端点。代码如下所示,以及web.xml中的代码。鉴于我在本地端口8888上托管,我应该访问哪个URL listDeviceInfo()?我尝试过以下方法:

  • http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo => 404
  • http:// localhost:8888 / _ah / api / deviceinfoendpoint / v1 / listDeviceInfo => 404
  • http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/listDeviceInfo => 405 GET not supported
  • http:// localhost:8888 / _ah / spi / deviceinfoendpoint / v1 / listDeviceInfo => 405 GET不支持
  • http://localhost:8888/_ah/spi/deviceinfoendpoint/v1/DeviceInfo => 405 GET (...)
  • http:// localhost:8888 / _ah / spi / deviceinfoendpoint / v1 / DeviceInfo => 405 GET(...)
  • http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo = > 405 GET(...)
  • http:// localhost:8888 / _ah / spi / v1 / deviceinfoendpoint / listDeviceInfo => 405 GET(...)

Exerpt of DeviceInfoEndpoint.java:

DeviceInfoEndpoint.java的Exerpt:

@Api(name = "deviceinfoendpoint")
public class DeviceInfoEndpoint {

/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method.
 *
 * @return List of all entities persisted.
 */
@SuppressWarnings({ "cast", "unchecked" })
public List<DeviceInfo> listDeviceInfo() {
    EntityManager mgr = getEntityManager();
    List<DeviceInfo> result = new ArrayList<DeviceInfo>();
    try {
        Query query = mgr
                .createQuery("select from DeviceInfo as DeviceInfo");
        for (Object obj : (List<Object>) query.getResultList()) {
            result.add(((DeviceInfo) obj));
        }
    } finally {
        mgr.close();
    }
    return result;
}
}

Web.xml:

web.xml中:

<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 <servlet>
  <servlet-name>SystemServiceServlet</servlet-name>
  <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
  <init-param>
   <param-name>services</param-name>
   <param-value>com.example.dummyandroidapp.DeviceInfoEndpoint</param-value>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>SystemServiceServlet</servlet-name>
  <url-pattern>/_ah/spi/*</url-pattern>
 </servlet-mapping>
</web-app>

2 个解决方案

#1


8  

API request paths should generally conform to the following:

API请求路径通常应符合以下条件:

http(s)://{API_HOST}:{PORT}/_ah/api/{API_NAME}/{VERSION}/

If you're interested in fetching/updating/deleting a specific resource, add an ID to the end. In your example, that suggests you should be querying:

如果您对获取/更新/删除特定资源感兴趣,请在末尾添加ID。在您的示例中,这表明您应该查询:

http://localhost:8888/_ah/api/deviceinfoendpoint/v1/

(which maps to list when you're making a GET request).

(当您发出GET请求时,它会映射到列表)。

In general, the APIs Explorer available at /_ah/_api/explorer makes it easy to discover and query these URLs.

通常,/ _ah / _api / explorer中提供的API Explorer可以轻松发现和查询这些URL。

#2


1  

You can controle the path by use:

您可以通过使用来控制路径:

  @ApiMethod(path="listDeviceInfo",  httpMethod = HttpMethod.GET)
    public List<DeviceInfo> listDeviceInfo(){
    //... definition

  }

Then you can call that from you client as: http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo

然后你可以从你的客户端调用它:http:// localhost:8888 / _ah / api / deviceinfoendpoint / v1 / listDeviceInfo

If you like send parameters then:

如果您喜欢发送参数,那么:

@ApiMethod(path="listDeviceInfo",  httpMethod = HttpMethod.GET)
        public List<DeviceInfo> listDeviceInfo(@Named("info") String info){
        //... definition

  }

http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo?info=holamundo

HTTP://本地主机:8888 / _ah / API / deviceinfoendpoint / V1 / listDeviceInfo信息= holamundo

#1


8  

API request paths should generally conform to the following:

API请求路径通常应符合以下条件:

http(s)://{API_HOST}:{PORT}/_ah/api/{API_NAME}/{VERSION}/

If you're interested in fetching/updating/deleting a specific resource, add an ID to the end. In your example, that suggests you should be querying:

如果您对获取/更新/删除特定资源感兴趣,请在末尾添加ID。在您的示例中,这表明您应该查询:

http://localhost:8888/_ah/api/deviceinfoendpoint/v1/

(which maps to list when you're making a GET request).

(当您发出GET请求时,它会映射到列表)。

In general, the APIs Explorer available at /_ah/_api/explorer makes it easy to discover and query these URLs.

通常,/ _ah / _api / explorer中提供的API Explorer可以轻松发现和查询这些URL。

#2


1  

You can controle the path by use:

您可以通过使用来控制路径:

  @ApiMethod(path="listDeviceInfo",  httpMethod = HttpMethod.GET)
    public List<DeviceInfo> listDeviceInfo(){
    //... definition

  }

Then you can call that from you client as: http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo

然后你可以从你的客户端调用它:http:// localhost:8888 / _ah / api / deviceinfoendpoint / v1 / listDeviceInfo

If you like send parameters then:

如果您喜欢发送参数,那么:

@ApiMethod(path="listDeviceInfo",  httpMethod = HttpMethod.GET)
        public List<DeviceInfo> listDeviceInfo(@Named("info") String info){
        //... definition

  }

http://localhost:8888/_ah/api/deviceinfoendpoint/v1/listDeviceInfo?info=holamundo

HTTP://本地主机:8888 / _ah / API / deviceinfoendpoint / V1 / listDeviceInfo信息= holamundo