Code Validation and Quick Fixes for Endpoints Backends
Server-side Endpoints API definitions must conform to a number of syntactic rules. Android Studio knows these and validates your code as you type to help you avoid making mistakes. Android Studio provides Endpoints-specific inspections and quick-fixes.
As-you-type code validation
For example, the default backend type
App Engine Java Endpoints Module
,
contains the following minimal annotated Endpoints API located in your project
at
<backend-name>/src/main/java/<package-name>/MyEndpoint.java
:
import javax.inject.Named;
@Api(name = "myApi", version = "v1",
namespace = @ApiNamespace(ownerDomain = "<package-name>",
ownerName = "<package-name>",
packagePath=""))
public class MyEndpoint {
@ApiMethod(name = "sayHi")
public MyBean sayHi(@Named("name") String name) {
MyBean response = new MyBean();
response.setData("Hi, " + name);
return response;
}
}
In the code,
@Named
is required for all non-entity type parameters passed to
server-side methods. If you forget to add this annotation when modifying
sayHi
in this code, Android Studio will underline the problematic statement
as you type, as shown below:
Quick fixes
In addition, to help you easily fix the problems with Cloud Endpoints, Android
Studio will provide quick-fixes for the most common Cloud Endpoints development
mistakes. To see these quick-fix suggestions, using the code example above with
the missing
@Named
annotation, press
Alt
+
Enter
if
you’re running on Linux/Windows or
⌥
+
Enter
if you’re running on Mac:
As expected, choosing the first quick-fix (
Add @Named
) will automatically add
@Named
to the method parameter.