The server interface

The server interface is created using a Python web server framework called Sanic, which helps to code the web server logic in an asynchronous way:

Background: Sanic is a lightweight web server framework that can be used to build a high-speed web server. It supports asynchronous programming by supporting Shiny async request handlers. It makes use of an event loop called uvloop to achieve better performance.
class Server(object): def __init__(self): = Sanic() self.blockchain = Blockchain() self.sockets = [], '/blocks', methods=['GET']), '/mineBlock', methods=['POST']), '/peers', methods=['GET']), ...

Get Foundations of Blockchain now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.