Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

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:

  • 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/DeviceInfo => 405 GET (...)
  • http://localhost:8888/_ah/spi/v1/deviceinfoendpoint/listDeviceInfo = > 405 GET(...)

Exerpt of DeviceInfoEndpoint.java:

@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:

<?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>
like image 373
Nilzor Avatar asked Feb 04 '13 09:02

Nilzor


People also ask

What are Google Cloud Endpoints?

Endpoints is an API management system that helps you secure, monitor, analyze, and set quotas on your APIs using the same infrastructure Google uses for its own APIs.


2 Answers

API request paths should generally conform to the following:

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:

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

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

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

like image 100
Dan Holevoet Avatar answered Sep 28 '22 17:09

Dan Holevoet


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

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

like image 35
Campino Avatar answered Sep 28 '22 15:09

Campino