Welcome to apicore’s documentation!

Set of core libraries usefull for building REST API and Microservices based on Flask.

The code is open source, release under MIT and written in Python 3.

apt-get install build-essential python3-dev
pip install apicore

Features

  • Cross-origin resource sharing (CORS) ready
  • Data caching with redis server or direct in memory
  • Configuration file loader
  • A simple Logger
  • Raise exception conform to HTTP status codes
  • Authorization using JSON Web Token(JWT) issued from an OpenID Connect provider.

Example

#!/usr/bin/env python

from apicore import api, Logger, config, Http409Exception, Authorization

config.load('config.yaml')
Logger.info("{} Starting".format(config.server_name))
api.prefix = "/api"


@api.route('/')
def hello():
    return "API v0.1"


@api.route('/error/')
def error():
    raise Http409Exception()


@api.route('/jwt/')
def jwt():
    userProfile = Authorization()
    print(userProfile);
    return "JWT Valid!"


if __name__ == "__main__":
    api.debug = config.debug
    api.run()

Configuration

Configuration is set in a YAML file (see apicore.config.Config).

Name Default value Description
server_name ‘API server’ Service name.
debug True Active debug mode.
issWhitelist None Whitelist for OIDC issuers. If not set, every issuers are allowed except ones from blacklist.
issBlacklist None Blacklist for OIDC issuers. synaxte : same as ‘iss’ claim in the JWT.
tokenExpire True Check ‘exp’ claim in JWT to validate token.
redis None Redis server used for caching data : redis://:password@localhost:6379/0. If not set use memory.

APIs

Todo

  • i18n HTTP response messages.
  • Configure using command line argument and environnement variables which override configuration file.