Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Using custom HTTP methods with Endpoints #186

Open
carise opened this issue May 20, 2020 · 0 comments
Open

Using custom HTTP methods with Endpoints #186

carise opened this issue May 20, 2020 · 0 comments

Comments

@carise
Copy link

carise commented May 20, 2020

I'm reading about using custom methods for APIs and would like to implement it in an API I'm working on. The endpoint in question is something like myapi/v1/myresource/{resourceId}:myCustomMethod

But this seems to be invalid:

[INFO] GCLOUD: java.lang.IllegalArgumentException: 'myapi/v1/myresource/{resourceId}:myCustomMethod' contains invalid parameter syntax: {resourceId}:myCustomMethod
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:196)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:193)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:177)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathDispatcher$Builder.add(PathDispatcher.java:69)
[INFO] GCLOUD: 	at com.google.api.server.spi.EndpointsServlet.createDispatcher(EndpointsServlet.java:117)
[INFO] GCLOUD: 	at com.google.api.server.spi.EndpointsServlet.init(EndpointsServlet.java:58)
[INFO] GCLOUD: 	at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:121)
[INFO] GCLOUD: 	at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82)
[INFO] GCLOUD: 	at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:103)
[INFO] GCLOUD: 	at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:220)
... etc

If I change the URI to myapi/v1/myresource/{resourceId}/something:myCustomMethod, the exception changes to:

[INFO] GCLOUD: java.lang.IllegalArgumentException: 'myapi/v1/myresource/{resourceId}/something:myCustomMethod' contains invalid path segment: results:propagationSummaries
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:201)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:193)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:193)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:203)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathTrie$Builder.add(PathTrie.java:177)
[INFO] GCLOUD: 	at com.google.api.server.spi.dispatcher.PathDispatcher$Builder.add(PathDispatcher.java:69)
[INFO] GCLOUD: 	at com.google.api.server.spi.EndpointsServlet.createDispatcher(EndpointsServlet.java:117)
[INFO] GCLOUD: 	at com.google.api.server.spi.EndpointsServlet.init(EndpointsServlet.java:58)

What's the right way to use custom methods? Should I instead create the endpoint to be something like: myapi/v1/myresource/{resourceId}/myCustomMethod (with the / instead of :)?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant