Skip to main content

Simply build a powerful JSON-REST-API with django

Project description

djsonREST

djsonREST provides simple powerful features to implement your own REST-API (data encoded as json) within minutes.

The routes are versioned by default.

It also includes an addon for authentication using JWTs using consumers and users.

Base Structure of a rest route url: your_path/ + VersionMajor.Minor + /endpoint_url

Installation

Use the python package manager pip to install djsonrest.

pip install djsonrest

Dependencies

djutils

Usage

Add djsonrest to your INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'djsonrest',
]

If you want to override default routes provided by djsonrest, order this app before your project app.

Add djsonrest.middleware.RESTRoutesMiddleware to your MIDDLEWARE.

MIDDLEWARE = [
    ...
    'djsonrest.middleware.RESTRoutesMiddleware',
]

If you want to customize the exception handling of rest routes override the RESTRoutesMiddleware class and configure your own middleware class instead.

Add a path for the api endpoints to your urls.py's urlpatterns.

from djsonrest import rest

urlpatterns = [
    ...
    path('api/', rest.routes.urls),
]

Define your own rest route using the route decorator @rest.route(...). All rest routes have to be defined in a module inside your app/project called rest_routes. Those module will be automatically loaded on django initialization and so the routes are being registered.

from djsonrest import rest


class Users(rest.RESTRouteGroup):
    @rest.route('/users', version=1.0, method='GET')
    def users_get(self, request, *args, **kwargs):
        return [...] # Return any json-encodable object

Using routes defined as classmethods, you can override them in inherited classes. This way you can provide extendable routes. To override the existing route, keep the route decorator the same. Change the route decorator if you want to add a second route.

class MyUsers(Users):
    @rest.route('/users', version=1.0, method='GET')
    def users_get(self, request, *args, **kwargs):
        result = super().users_get(request, *args, **kwargs)
        result.append([...])
        return result


class MyUsersV2(Users):
    @rest.route('/users', version=2.0, method='GET')
    def users_get(self, request, *args, **kwargs):
        result = super().users_get(request, *args, **kwargs)
        return {"users": result}

License

GNU GPLv3, see LICENSE

Maintainer

This package is maintained by Manuel Stingl. For more information see https://opensource.voltane.eu

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

djsonREST-0.1.3.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

djsonREST-0.1.3-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file djsonREST-0.1.3.tar.gz.

File metadata

  • Download URL: djsonREST-0.1.3.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.3

File hashes

Hashes for djsonREST-0.1.3.tar.gz
Algorithm Hash digest
SHA256 06c9f0b63a508b1a446bc88d83f6e692548049bc4eb9479dfdfd1396916cdc6c
MD5 f99dd50310224b2d5fad3129a7682e64
BLAKE2b-256 8022b86f73014ae19337273cc78ece62acbbcbaa2a4d5e402a2318e8fc1ed8ca

See more details on using hashes here.

File details

Details for the file djsonREST-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: djsonREST-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.1 CPython/3.7.3

File hashes

Hashes for djsonREST-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0fda3f2f747fffc16f00bcc200cf8419b40671fcab15eca6692ae1d32d92d3be
MD5 ac9e3fa1a640063069ef198d55b4a6b8
BLAKE2b-256 22e93da92356cb0ee0a66fe4b9054afe94c9b55d2e954d0961f3b07866e8b180

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