Http Entrypoint¶
Until now, we were working with rpc with amqp which uses rpc as an entrypoint to the service method. We will change that pattern and will use http entrypoint this time.
Service Code¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # http_service.py
from nameko.web import handlers
class HttpService(object):
name = 'http_service'
@handlers.http('GET', '/')
def get_method(self, request):
return 'index'
@handlers.http('POST', '/post')
def post_method(self, request):
return request.get_data(as_text=True)
|
line-1: imports
handlers from web which contains http entrypoint.line-3: Defines the service class.
line-4: declares the name of the service
line-6: defines
http entrypoint with suitable http method and path.line-7: service method to do real task.
Working¶
Working of http entrypoint is much simpler.
nameko runthe service code. It will start a process at port8000.- use
curl -i localhost:8000/to send a http request. - This service being a
GETrequest,get_methodwill process this request. - It will send
'index'string as response with other http headers.