Exposing HTTP entrypoints
We will now create a new microservice responsible for handling HTTP requests. First of all, let's amend our imports in the service.py
file:
from nameko.rpc import rpc, RpcProxy from nameko.web.handlers import http
Beneath the KonnichiwaService
we made earlier, insert the following:
class WebServer: name = 'web_server' konnichiwa_service = RpcProxy('konnichiwa_service') @http('GET', '/') def home(self, request): return self.konnichiwa_service.konnichiwa()
Notice how the follows a similar pattern to the KonnichiwaService
. It has a name
attribute and a method decorated in order to expose it as an entrypoint. In this case, it is decorated with the http
entrypoint. We specify inside the http
decorator that it is a GET
request and the location of that request - in this case, the root of our website.
There is also one more crucial difference: This service holds a reference to the Konnichiwa Service via an RpcProxy
object. RpcProxy
allows...