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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.