0

My issue is rather simple, but due to my inexperience I am not sure how to accomplish what I want to do.

The backend that I am utilizing is Google App Engine, but I believe this is a general python question.

How can I structure my JSON response to return the exact object JSON back that was initially sent in the request?

    class UserCreateRequestMessage(messages.Message):
    email = messages.StringField(1, required=True)
    password = messages.StringField(2, required=True)


class UserCreateResponseMessage(messages.Message):
    email = messages.StringField(1)
    username = messages.StringField(2)
    # id = messages.IntegerField(3)

HERE IS THE API, THE PROBLEM IS WITH THE RETURN LINE

    @endpoints.api(name='photoswap', version='v1')
class PhotoswapAPI(remote.Service):
    @endpoints.method(UserCreateRequestMessage, UserCreateResponseMessage,
                      path='user', http_method='POST',
                      name='user.create')
    def user_create(self, request):
        entity = User(email=request.email, password=request.password)
        entity.put()
        return UserCreateResponseMessage(email=entity.email, password=entity.password)

1 Answer 1

1

The issue was due to a message class that did not contain "password" and instead contained "username".

I fixed the issue below.

class UserCreateRequestMessage(messages.Message):
    email = messages.StringField(1, required=True)
    password = messages.StringField(2, required=True)


class UserCreateResponseMessage(messages.Message):
    email = messages.StringField(1)
    password = messages.StringField(2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.