简体   繁体   English

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

[英]What is the URL to access a Hello-World Google Cloud Endpoint service?

I've generated a Google Endpoint AppEngine project in Eclipse by using the Generate AppEngine BackEnd as described in this blog post . 我已经使用Generate AppEngine BackEnd在Eclipse中生成了一个Google Endpoint AppEngine项目,如本博 Generate AppEngine BackEnd中所述。 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? 然而,该帖子没有描述的内容以及官方Google Docs描述得很差的是哪个URL我可以在本地访问该服务?

The service generated has one generated endpoint called DeviceInfoEndpoint. 生成的服务有一个名为DeviceInfoEndpoint的生成端点。 The code is shown below as well as the code in web.xml. 代码如下所示以及web.xml中的代码。 Which URL should I access listDeviceInfo() with given that I'm hosting on port 8888 locally? 鉴于我在本地端口8888上托管,我应该访问哪个URL listDeviceInfo()? I've tried the following: 我尝试过以下方法:

  • 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>

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. 如果您对获取/更新/删除特定资源感兴趣,请在末尾添加ID。 In your example, that suggests you should be querying: 在您的示例中,这表明您应该查询:

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

(which maps to list when you're making a GET request). (当您发出GET请求时,它会映射到list )。

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。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM