# providing context data via http entrypoints

**URL:** <https://discourse.nameko.io/t/providing-context-data-via-http-entrypoints/117>\
**Category:** googlegroup\
**Created:** [December 26, 2015, 7:43pm UTC](https://discourse.nameko.io/t/providing-context-data-via-http-entrypoints/117 "2015-12-26T19:43:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mustafa\_Arici](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mustafa\_Arici](https://discourse.nameko.io/u/Mustafa_Arici)\
**Post date:** [December 26, 2015, 7:43pm UTC](https://discourse.nameko.io/t/providing-context-data-via-http-entrypoints/117/1 "2015-12-26T19:43:21Z")

</div>

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/nameko/nameko/blob/master/nameko/web/server.py>

---

<div class="post-metadata">

**Author:** ![David\_Szotten](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/david_szotten/32/6_2.png) [@David\_Szotten](https://discourse.nameko.io/u/David_Szotten)\
**Post date:** [December 26, 2015, 10:07pm UTC](https://discourse.nameko.io/t/providing-context-data-via-http-entrypoints/117/2 "2015-12-26T22:07:48Z")

</div>

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):  
&nbsp;&nbsp;&nbsp;&nbsp;def context\_data\_from\_headers(self, request):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'foo': request.headers.get('Some-Key', 'Default')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

class MyHttpRequestHandler(HttpRequestHandler):  
&nbsp;&nbsp;&nbsp;&nbsp;server = MyWebServer()

# if you want  
my\_http = MyHttpRequestHandler.decorator

# in your service

class MyService(object):  
&nbsp;&nbsp;&nbsp;&nbsp;@my\_http  
&nbsp;&nbsp;&nbsp;&nbsp;def my\_entrypoint(self):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](https://github.com/onefinestay/nameko/blob/master/nameko/web/server.py#L107)

---

<div class="post-metadata">

**Author:** ![Mustafa\_Arici](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mustafa\_Arici](https://discourse.nameko.io/u/Mustafa_Arici)\
**Post date:** [December 27, 2015, 1:21am UTC](https://discourse.nameko.io/t/providing-context-data-via-http-entrypoints/117/3 "2015-12-27T01:21:50Z")

</div>

Well that didn't even cross my mind and I don't know why. 🙂  
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):  
> > &nbsp;&nbsp;&nbsp;&nbsp;def context\_data\_from\_headers(self, request):  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'foo': request.headers.get('Some-Key', 'Default')  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > class MyHttpRequestHandler(HttpRequestHandler):  
> > &nbsp;&nbsp;&nbsp;&nbsp;server = MyWebServer()
> > 
> > # if you want  
> > my\_http = MyHttpRequestHandler.decorator
> > 
> > # in your service
> > 
> > class MyService(object):  
> > &nbsp;&nbsp;&nbsp;&nbsp;@my\_http  
> > &nbsp;&nbsp;&nbsp;&nbsp;def my\_entrypoint(self):  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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](https://github.com/onefinestay/nameko/blob/master/nameko/web/server.py#L107)
