Python

Since the beginning of 2020, FastAPI has been gaining momentum as one of the potential alternatives to Flask server for RESTful API. If you are an existing FastAPI user, you should be aware that it does not come with built-in internationalization, and that will likely not change soon, because internationalization strategies are application-dependent.

The following tutorial focuses on server-side i18n .

This tutorial will show you how to i18n your FastAPI web application easily using the following Python libraries:

When you create a big python application, you can began to run into challenges with longer scripts that extended beyond the expiration of a single JWT.

To elegantly solve this, You can use decorators to check the token’s expiration and request a new token if necessary. This article goes over the framework I set up so that you can apply a similar mechanism in your own scripts.

Setting the Scene


import time
import requests

class myAPI():
    host = None
    key = None
    secret = None
    access_token = None
    access_token_expiration = None

    def __init__(self,host,key,secret):
        # the function that is executed when
        # an instance of the class is created
        pass

    def getAccessToken(self):
        # the function that is 
        # used to request the JWT
        pass

    class Decorators():
        @staticmethod
        def refreshToken(decorated):
            # the function that is used to check
            # the JWT and refresh if necessary
            pass

Our class will work by requiring the fields necessary to request the JWT. Without access, there is nothing more our class will do.

« 3/6 »