Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

TODO

Project description

1   Welcome to nlx_middleware’s documentation!

Version:0.1.0
Source:https://github.com/maykinmedia/nlx_middleware
Keywords:<keywords>
PythonVersion:3.6

build-status Requirements status Coverage status

python-versions django-versions pypi-version

A Django middleware to integrate your service with NLx.

This middleware takes care of rewriting URLs in the linked-data responses if you’re operating in the NLx network. This makes it possible to use the NLx-outway URLs everywhere, while still saving/linking data against their canonical URLs.

2   Features

  • Rewriting of NLx outway URLs in the request body to canonical URLs
  • Rewriting of canonical URLs in the response body to NLx outway URLs
  • Rewrites URLs in GET query params
  • Leverages the OpenAPI schema to figure out what needs rewriting

2.1   TODO:

  • Set up registry of external services to rewrite as well
  • Support OAS 3.0 (via gemma-zds-client)

3   Installation

3.1   Requirements

  • Python 3.6 or above
  • setuptools 30.3.0 or above
  • Django 1.11 or above
  • django-rest-framework
  • the API schema must be available at {API_ROOT}/schema/openapi.yaml (currently Swagger 2.0 is supported)
  • gemma-zds-common (recommended)

3.2   Install

pip install nlx-middleware

4   Usage

Add the middleware to you MIDDLEWARE setting:

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    ...
    'nlx_middleware.middleware.NLxInwayURLRewriteMiddleware',
]

We recommend to put it as close to the end as possible. Review the Django middleware documentation to see why the order matters.

Optionally, but recommended, add nlx_middleware to your INSTALLED_APPS. This makes models available where you can map external services to their canonical domains/addresses so that URLs not provided/served by your own project can also be rewritten.

If you don’t need this, then there’s (currently) no need to add it to your INSTALLED_APPS.

Next, ensure the following settings are defined:

NLX_SERVICE = os.getenv('NLX_SERVICE', 'zrc')
NLX_INWAY_ADDRESS = os.getenv('NLX_ADDRESS', 'localhost:8000')
NLX_ORGANIZATION = os.getenv('NLX_ORGANIZATION', 'vng-realisatie')
NLX_OUTWAY_ADDRESS = os.getenv('NLX_OUTWAY_ADDRESS', 'http://localhost:2018')

Note

In the example, we pull them from the environment, but you can of course follow your own preferred method.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for nlx-middleware, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size nlx_middleware-0.2.0-py2.py3-none-any.whl (11.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size nlx-middleware-0.2.0.tar.gz (10.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page