In the endpoints method, how to access request header information?
2 Answers
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
Comments
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)