Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

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

Open

Description

@dalbani

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!

Activity

  1. changed the title [-]Method with request body *and* query parameters become combined[/-] [+]Method's request body *and* query parameters become combined[/+] on Nov 5, 2016
  2. dalbani commented on Nov 5, 2016

    @dalbani
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions