3

In the endpoints method, how to access request header information?

2 Answers 2

4

Python:

In the endpoint method, self.request_state.headers provides this information.

E.g., self.request_state.headers.get('authorization')

Java: Add an HttpServletRequest (req) parameter to your endpoint method. The headers are accessible through the method getHeader() e.g., req.getHeader("Authorization") See this question

Sign up to request clarification or add additional context in comments.

Comments

0

What is working for me in python is the following:

The request I use: http://localhost:8080/api/hello/v1/header?message=Hello World!

python code:

    @endpoints.api(name='hello', version='v1', base_path='/api/')
    class EchoApi(remote.Service):
        @endpoints.method(
            # This method takes a ResourceContainer defined above.
            message_types.VoidMessage,
            # This method returns an Echo message.
            EchoResponse,
            path='header',
            http_method='GET',
            name='header')
        def header(self, request):
            header = request._Message__unrecognized_fields
            output_message = header.get(u'message', None)[0]
            return EchoResponse(message=output_message)

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.