providing context data via http entrypoints

Hi there,

How do we provide context data via http entrypoints using nameko?

I found this[0] method while looking at the source which always returns
empty dict. Does it mean this is unsupported at the moment?

Regards

[0] -

Hi Mustafa,

I don't recall this particular case, but I would guess it's empty because
we thought it application-specific enough not to set any defaults. The idea
would be to create your own entrypoint, by creating a subclass and
overriding that method.

Something like

class MyWebServer(WebServer):
    def context_data_from_headers(self, request):
        return {
            'foo': request.headers.get('Some-Key', 'Default')
        }

class MyHttpRequestHandler(HttpRequestHandler):
    server = MyWebServer()

# if you want
my_http = MyHttpRequestHandler.decorator

# in your service

class MyService(object):
    @my_http
    def my_entrypoint(self):
        pass

Best,
David

···

On Saturday, 26 December 2015 19:43:21 UTC, Mustafa Arıcı wrote:

Hi there,

How do we provide context data via http entrypoints using nameko?

I found this[0] method while looking at the source which always returns
empty dict. Does it mean this is unsupported at the moment?

Regards

[0] -
https://github.com/onefinestay/nameko/blob/master/nameko/web/server.py#L107

Well that didn't even cross my mind and I don't know why. :slight_smile:
I think sometimes it's hard to know whether you should subclass or you
should dig around the api in the search of a facility that does what you
want.

Thanks for the reply David!

···

On Sunday, December 27, 2015 at 12:07:49 AM UTC+2, David Szotten wrote:

Hi Mustafa,

I don't recall this particular case, but I would guess it's empty because
we thought it application-specific enough not to set any defaults. The idea
would be to create your own entrypoint, by creating a subclass and
overriding that method.

Something like

class MyWebServer(WebServer):
    def context_data_from_headers(self, request):
        return {
            'foo': request.headers.get('Some-Key', 'Default')
        }

class MyHttpRequestHandler(HttpRequestHandler):
    server = MyWebServer()

# if you want
my_http = MyHttpRequestHandler.decorator

# in your service

class MyService(object):
    @my_http
    def my_entrypoint(self):
        pass

Best,
David

On Saturday, 26 December 2015 19:43:21 UTC, Mustafa Arıcı wrote:

Hi there,

How do we provide context data via http entrypoints using nameko?

I found this[0] method while looking at the source which always returns
empty dict. Does it mean this is unsupported at the moment?

Regards

[0] -
https://github.com/onefinestay/nameko/blob/master/nameko/web/server.py#L107