Conscious about REST? Then you want to have control over HTTP methods associated with your API calls. Should you choose not to use @ApiMethod, Endpoints falls back to an educated guess approach based on the API method name, as stated in the docs. I couldn’t find much details about how the resolution works, but common sense worked for me. This post presents my findings when experimenting with automatic HTTP method resolution.

The educated guess approach proved to work well. Please find below a summary of the naming conventions I found working reliably. The code examples are based on the official tutorial.

GET
Method name starts with get or list

[java]
public HelloGreeting getGreeting(@Named(“id”) Integer id) {..}
GET http://localhost:8080/_ah/api/helloworld/v1/hellogreeting/0

public ArrayList<HelloGreeting> listGreeting() {..}
GET http://localhost:8080/_ah/api/helloworld/v1/hellogreeting
[/java]

POST
There are no special conventions. POST is a fallback in case the method won’t resolve to either GET or DELETE.

DELETE
Method name starts with remove or delete

[java]
public ArrayList<HelloGreeting>
removeGreeting(@Named(“id”) Integer id) {..}
DELETE http://localhost:8080/_ah/api/helloworld/v1/greeting/0

public ArrayList<HelloGreeting>
deleteGreeting(@Named(“id”) Integer id) {..}
DELETE http://localhost:8080/_ah/api/helloworld/v1/greeting/0
[/java]

PUT
As far as I can tell it is impossible to get to a PUT method without using @ApiMethod.

[java]
@ApiMethod(name = “greetings.put”, httpMethod = “put”)
public ArrayList<HelloGreeting>
putGreeting(@Named(“id”) Integer id,
@Named(“message”) String message) {..}
PUT http://localhost:8080/_ah/api/helloworld/v1/putGreeting/0/hi%20there
[/java]

This post is part of Google App Engine and Android – Pros and Cons, Challenges


Tomas Zezula

Hello! I'm a technology enthusiast with a knack for solving problems and a passion for making complex concepts accessible. My journey spans across software development, project management, and technical writing. I specialise in transforming rough sketches of ideas to fully launched products, all the while breaking down complex processes into understandable language. I believe a well-designed software development process is key to driving business growth. My focus as a leader and technical writer aims to bridge the tech-business divide, ensuring that intricate concepts are available and understandable to all. As a consultant, I'm eager to bring my versatile skills and extensive experience to help businesses navigate their software integration needs. Whether you're seeking bespoke software solutions, well-coordinated product launches, or easily digestible tech content, I'm here to make it happen. Ready to turn your vision into reality? Let's connect and explore the possibilities together.