0
votes

I've create a simple API with Google Cloud Endpoints. Now, I want to create a new version for this API.

I have the following classes:

@Api(name = "helloworld",
    version = "v1")
public class HelloWorldApi {
    @ApiMethod(name = "sayHello", path = "/sayHello", httpMethod = "get")
    public HelloWorld SayHello(){
        return new HelloWorld("Hello World v1");
    }
}

and

@Api(name = "helloworld",
    version = "v2")
public class HelloWorldApiV2 {
    @ApiMethod(name = "sayHello", path = "/sayHello", httpMethod = "get")
    public HelloWorld SayHello(){
        return new HelloWorld("Hello World v2");
    }
}

I then deploy and go to [myapplication].appspot.com/_ah/api/explorer. Here, I can see both versions in "All Versions" with "v2" as the default.

The problem is that it doesn't matter which one I use. They both return either "Hello World v1" or "Hello World v2" randomly.

What am I doing wrong?

1

1 Answers

1
votes

Turns out that the problem was related to the path. I removed the path element from the api definition in both versions and it works fine.

I can now see that the calls are being made to http://localhost:8888/_ah/api/helloworld/v1/SayHello and http://localhost:8888/_ah/api/helloworld/v2/SayHello respectively. I guess the hard coded path removed the /v1 and /v2 and both versions would be called at the same time, returning only one of them.