Exposing the microservice data

With the model declared, let's implement the views.py file. As mentioned in a previous chapter, let us use flask as the framework of microservices for News.

First, we declare the imports necessary for the operation of the views.py file:

import datetime 
import mongoengine 
from flask import Blueprint, jsonify, request 
from models import News 

Now, we will instantiate the class from the flask called Blueprint. This tool will need a few decorators to declare the access routes for the application:

famous_news = Blueprint('famous_news', __name__)

The first route that will be declared is responsible for providing a News by ID—a simple process. First, we use the variable famous_news with the Blueprint as a decorator ...

Get Microservice Patterns and Best Practices 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.