Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method's request body *and* query parameters become combined #20

Open
dalbani opened this issue Nov 5, 2016 · 1 comment
Open

Method's request body *and* query parameters become combined #20

dalbani opened this issue Nov 5, 2016 · 1 comment

Comments

@dalbani
Copy link

dalbani commented Nov 5, 2016

Given this example from the python-docs-sample repository:

class Greeting(messages.Message):
    """Greeting that stores a message."""
    message = messages.StringField(1)

@endpoints.method(
    endpoints.ResourceContainer(
        Greeting,
        times=messages.IntegerField(2, variant=messages.Variant.INT32,
                                required=True))
    Greeting,
    path='greetings/multiply/{times}',
    http_method='POST',
    name='greetings.multiply')
def multiply_greeting(self, request):
    return Greeting(message=request.message * request.times)

I find strange that the Greeting request body and times query parameter get "mixed" into a CombinedContainer object personified by request.

If I compare with Java, all of the parameters appear independently in the Java method signature.
For example:

@ApiMethod(name = "greetings.multiply", httpMethod = "post")
public HelloGreeting insertGreeting(@Named("times") Integer times, HelloGreeting greeting) {
  HelloGreeting response = new HelloGreeting();
  StringBuilder responseBuilder = new StringBuilder();
  for (int i = 0; i < times; i++) {
    responseBuilder.append(greeting.getMessage());
  }
  response.setMessage(responseBuilder.toString());
  return response;
}

That appears more logical and less error-prone to me.
Could it possible to have the same behavior in Python? Or was it designed that way on purpose?

As a workaround, what would be a generic way to turn any CombinedContainer into an object as defined in the ResourceContainer?

Thanks!

@dalbani dalbani changed the title Method with request body *and* query parameters become combined Method's request body *and* query parameters become combined Nov 5, 2016
@dalbani
Copy link
Author

dalbani commented Nov 5, 2016

Speaking of CombinedContainer: how am I supposed to implement PATCH semantics when it doesn't differentiate the case:

  • when the request body explicitly contains { "message": null }, from
  • when the request body does not mention message at all.

In both cases, request.message equals to None.

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

No branches or pull requests

1 participant