Skip to main content

VNG API tooling

Project description

VNG-API-common biedt generieke implementaties en tooling voor RESTful APIs in een Common Ground gegevenslandschap.

De tooling wordt o.a. gebruikt in de referentie-implementaties van componenten voor zaakgericht werken, maar ook in VNG-APIs voor referentielijsten en de Gemeentelijke Selectielijst.

Het is een third-party library voor Django projecten, gebaseerd op Django Rest Framework en drf-yasg voor schema-generatie.

1 Features

  • Centraal beheer van constanten die de verschillende componenten overstijgen

  • GeoJSON OpenAPI definities

  • Support voor Geo CRS negotation

  • Ingebouwde support voor nested viewsets met declaratievere syntax voor registratie

  • Vaak voorkomende validators:
    • RSIN/BSN validator

    • Numerieke waarde validator

    • Niet-negatieve waarde validator

    • Alfanumerieke waarde (zonder diacritics)

    • URL-validator (test dat URL bestaat) met pluggable link-checker

    • UntilNowValidator - valideer datetimes tot en met nu.

    • UniekeIdentificatieValidator (in combinatie met organisatie)

    • InformatieObjectUniqueValidator om te valideren dat M2M entries slechts eenmalig voorkomen

    • ObjectInformatieObjectValidator om te valideren dat de synchronisatie van een object-informatieobject relatie pas kan nadat deze relatie in het DRC gemaakt is

    • IsImmutableValidator - valideer dat bepaalde velden niet gewijzigd worden bij een (partial) update, maar wel mogen gezet worden bij een create

    • ResourceValidator - valideer dat een URL een bepaalde resource ontsluit

  • Custom inspectors voor drf-yasg:
    • Support voor rest_framework_gis GeometryField

    • SUpport voor django-extra-fields Base64FieldMixin

    • URL-based related resource filtering (django-filter support)

    • verzameling van mogelijke error-responses per operation

  • Management command generate_swagger overloaded
    • neemt default versie mee en maakt server-informatie domein-agnostisch

    • optie om informatiemodel-resources naar markdown te renderen met backlinks naar gemmaonline.nl

  • Support voor ISO 8601 durations

  • Custom model fields:
    • RSINField

    • BSNField

    • LanguageField

    • VertrouwelijkheidsAanduidingField

    • DaysDurationField

  • Mocks voor de validators die netwerk IO hebben, eenvoudig via @override_settings toe te passen

  • Test utilities

  • Optionele notificaties applicatie:
    • ontvangen van webhook events

    • configureren en registreren van notificatiecomponent/webhooks

2 Installatie

2.1 Benodigdheden

  • Python 3.6 of hoger

  • setuptools 30.3.0 of higher

2.2 Installeren

pip install vng-api-common

Indien je de notifications app wil gebruiken, dan kan je extra dependencies installeren via:

pip install vng-api-common[notifications]

3 Gebruik

Zie de referentie-implementaties voor ZRC, DRC, BRC en ZTC.

3.1 Notifications

This library ships with support for notifications, in the form of view(set) mixins.

To enable them, add:

...,
'django.contrib.sites',
'vng_api_common.notifications',
...

to your INSTALLED_APPS setting.

Two additional settings are available:

  • NOTIFICATIONS_KANAAL: a string, the label of the ‘kanaal’ to register with the NC

  • NOTIFICATIONS_DISABLED: a boolean, default False. Set to True to completely disable the sending of notifications.

Next, in the admin interface, open the notifications configuration and enter the URL + credentials of the NC to use.

Make sure you also have the Sites set up correctly, as the domain configured there is used to build the documentation URL.

After entering the configuration, you can register your ‘kanaal’ - this action is idempotent:

python manage.py register_kanaal

Usage in code

Define at least one Kanaal instance, typically this would go in api/kanalen.py:

from vng_api_common.notifications.kanalen import Kanaal

from zrc.datamodel.models import Zaak

ZAKEN = Kanaal(
    'zaken',  # label of the channel/exchange
    main_resource=Zaak,  # main object for this channel/exchange
    kenmerken=(  # fields to include as 'kenmerken'
        'bronorganisatie',
        'zaaktype',
        'vertrouwelijkheidaanduiding'
    )
)

To send notifications, add the mixins to the viewsets:

  • vng_api_common.notifications.viewsets.NotificationCreateMixin: send notifications for newly created objects

  • vng_api_common.notifications.viewsets.NotificationUpdateMixin: send notifications for (partial) upates to objects

  • vng_api_common.notifications.viewsets.NotificationDestroyMixin: send notifications for destroyed objects

  • vng_api_common.notifications.viewsets.NotificationViewSetMixin: a combination of all three mixins above

and define the attribute notifications_kanaal on the viewset:

from .kanalen import ZAKEN


class ZaakViewSet(NotificationViewSetMixin, viewsets.ModelViewSet):
    ...
    notifications_kanaal = ZAKEN

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

vng-api-common-0.35.10.tar.gz (50.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vng_api_common-0.35.10-py2.py3-none-any.whl (72.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file vng-api-common-0.35.10.tar.gz.

File metadata

  • Download URL: vng-api-common-0.35.10.tar.gz
  • Upload date:
  • Size: 50.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.8

File hashes

Hashes for vng-api-common-0.35.10.tar.gz
Algorithm Hash digest
SHA256 7bdd5e23a1b9d379fae9eb2e80cb2a5a83f5f88a5ebe77a48adce40a79431668
MD5 aee38c373d8daa3931ec3292a9bfdbe6
BLAKE2b-256 31241d7f4f9385408bed2f3dc7adeedf29543308e617155d3a7533232c8936e9

See more details on using hashes here.

File details

Details for the file vng_api_common-0.35.10-py2.py3-none-any.whl.

File metadata

  • Download URL: vng_api_common-0.35.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 72.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.8

File hashes

Hashes for vng_api_common-0.35.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f45ad1e061e639930ad4396aba404778f09f08d8921f88cbf199989f74d8157f
MD5 a6293aab8cb05037a50bb771213fa48d
BLAKE2b-256 6bbaeaa06e46a94ac77f2bd38872cc6301287116e88aa4c8a2bbf435db9534c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page