Skip to main content

Add FAIR signpostings to response headers

Project description

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.

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.util import add_signposts

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

    return response

Multiple links with the same link type can be added as lists and the content type of a link can be defined by using tuples:

from django.http import HttpResponse
from django_signposting.util import add_signposts

def my_view(request):
    response = HttpResponse("Hello, world!")

    # Add signpostings as string
    add_signposts(response,
                  type="https://schema.org/Dataset",
                  author="https://orcid.org/0000-0001-9447-460X",
                  item=[
                      ("https://example.com/image.png", "image/png"),
                      ("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/image.png> ; rel="item" ; type="application/json+ld"

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.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

django_signposting-0.0.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_signposting-0.0.1.tar.gz
Algorithm Hash digest
SHA256 46de41f12cb5128dad6d5f0e4c3e51b1bb30244b4e9b46e52d64a097794bfdf5
MD5 03eb818e2be22232366ad1bfc11c2f58
BLAKE2b-256 0e2abf7468cf7624d0d4915da122de62b4c70169be9745df465c9c345d80c292

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_signposting-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24df2c62b793c31aea93665771fe54d72ac1ff3e491a427ab5e86a8d4a44f724
MD5 163d1812f7d6419b94423208110e1c3c
BLAKE2b-256 1d446dc4facb1b83356baa8d7ad9ea454829658f0e126c30e8fc8de3ce28aae3

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