Skip to main content

Add FAIR signpostings to response headers in Django

Project description

Python package

FAIR signposting for Django

django_signposting is a Django middleware library that facilitates the addition of FAIR signposting headers to HTTP responses. This middleware helps in making your data more FAIR (Findable, accessible, interoperable, reuseable) by embedding signposting headers in responses, guiding clients to relevant resources linked to the response content.

Based on the Signposting library.

Features

  • Automatically adds signposting headers to HTTP responses.
  • Supports multiple relation types with optional media type specification.
  • Easily integrable with existing Django applications.

Installation

pip install django_signposting

Usage

1. Add Middleware

Add the middleware to your Django project's MIDDLEWARE setting in settings.py:

MIDDLEWARE = [
    ...,
    'django_signposting.middleware.SignpostingMiddleware',
    ...,
]

2. Add Signposts to your Views

You can add signposting headers in your Django views using the provided add_signposts utility function. Here's how you can use it:

from django.http import HttpResponse
from django_signposting.utils import add_signposts
from signposting import Signpost, LinkRel

def my_view(request):
    response = HttpResponse("Hello, world!")
    
    # Add signpostings as string
    add_signposts(
        response,
        Signpost(LinkRel.type, "https://schema.org/Dataset"),
        Signpost(LinkRel.author, "https://orcid.org/0000-0001-9447-460X")
        Signpost(LinkRel.item, "https://example.com/download.zip", "application/zip")
    )

    return response

3. Signposts are formatted and added as Link headers by the middleware:

curl -I https://example.com
HTTP/2 200 
...
link: <https://schema.org/Dataset> ; rel="type" ,
      <https://orcid.org/0000-0001-9447-460X> ; rel="author" ,
      <https://example.com/download.zip> ; rel="item" ; type="application/zip"

License

Licensed under the MIT License.

Project details


Download files

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

Source Distribution

django_signposting-0.10.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

django_signposting-0.10.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file django_signposting-0.10.0.tar.gz.

File metadata

  • Download URL: django_signposting-0.10.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for django_signposting-0.10.0.tar.gz
Algorithm Hash digest
SHA256 075154cbf7a1bce9c439a844e5ba4fea7913e3c6181f445afc9bc76c7ce6076d
MD5 74da534279468f4621ceb44b118267ef
BLAKE2b-256 90d3327446aee66fe75f7ffac851a439c8608942a7e25ab086d987a2dceb0908

See more details on using hashes here.

File details

Details for the file django_signposting-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_signposting-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f999fdab62ac5a240f2b75a2f4b11ab881c6eea396e5f3063929654a56a4db70
MD5 79f9a7b80b47c5b62d9fcdd55bd2f18e
BLAKE2b-256 01a8ba10fc0b7a2d8d2d198ac9acb33dfe0f0fedd2d8ddd91a2eaf867196607d

See more details on using hashes here.

Supported by

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