A light REST library for Django.

Overview

django-nap

Read The Docs: https://django-nap.readthedocs.io/en/latest/

Change log: https://django-nap.readthedocs.io/en/latest/changelog.html

An API library for Django

A minimalist approach to object de/serialisers, RESTful views, and RPC views.

Benefits

  1. Modular

    Unlike some tools, the Serialiser definition is separate from the API.

    This not only makes it easier to have different 'shapes' of data for different endpoints, but also allows using them in more places, not just your API.

  1. Simple

    If you want an API that provides every feature ever, go look at Django REST Framework. But if you want something simple and fast, this is your tool.

Overview

Installing

It is NOT necessary to add nap to your INSTALLED_APPS. It does not provide models, templates, template tags, or static files.

Tests are currently run for Python 3.4-3.7 and pypy3, and against Django versions 2.0 and up.

Comments
  • ObjectPutMixin should use mapper._apply() instead of mapper._patch()

    ObjectPutMixin should use mapper._apply() instead of mapper._patch()

    An HTTP PUT is a complete replacement of a resource, so I think it should use mapper._apply(), which expects all required fields to have values.

    Additionally, there should probably be an ObjectPatchMixin for HTTP PATCH (with a def patch(..)) that uses mapper._patch() and behaves like the existing ObjectPutMixin.

    I'll probably have time to make a PR for this, but wanted to hear if this implementation (ObjectPutMixin with HTTP PATCH behavior) was intentional or an oversight.

    Lastly, I realize this is a backwards incompatible change, but it seems like a bug in its current implementation, since it doesn't match the HTTP spec:

    Thoughts?

    opened by ianawilson 3
  • Nap assumes everything in INSTALLED_APPS is a module

    Nap assumes everything in INSTALLED_APPS is a module

    As of 1.7, it's entirely normal to have a reference to an AppConfig class in INSTALLED_APPS.

    Since nap tries to import everything in INSTALLED_APPS during autodiscovery, attempting to run a Django app using these AppConfig classes results in ImportErrors.

    I have a commit written to address this but I believe some kind of logging might be a better way to handle this.

    opened by bobobo1618 3
  • digattr breaks when managers are involved

    digattr breaks when managers are involved

    opened by bobobo1618 3
  • Create more elaborate description about differences to other rest framewords

    Create more elaborate description about differences to other rest framewords

    Something that would allow lazy people like me to get a fast understanding (without having to read through all the documentation/code) of what's good and bad versus the other rest frameworks like tastypie and rest-framework

    opened by ionelmc 3
  • docs: Fix a few typos

    docs: Fix a few typos

    There are small typos in:

    • docs/extras/http.rst
    • docs/mapper/fields.rst
    • docs/quickstart.rst
    • docs/tutorial/mapper.rst
    • docs/tutorial/mappers.rst
    • docs/tutorial/views.rst
    • src/nap/rpc/views.py

    Fixes:

    • Should read raisable rather than raiseable.
    • Should read publishable rather than pubishable.
    • Should read passed rather than pased.
    • Should read from rather than fron.
    • Should read composable rather than composible.
    • Should read authenticated rather than authentencated.
    • Should read assigned rather than assignd.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 2
  • list_deflate() must be called with LabSerialiser instance as first argument (got QuerySet instance instead)

    list_deflate() must be called with LabSerialiser instance as first argument (got QuerySet instance instead)

    I have a simple model with two fields, I'm using a ModelSerialiser and a ModelPublisher with ModelPublisher.patterns() for the URLConf. When visiting the page I get an error "unbound method list_deflate() must be called with LabSerialiser instance as first argument (got QuerySet instance instead)"

    Traceback:
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
      99.                     response = view_func(request, *args, **kwargs)
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/nap/publisher.py" in view
      45.             return self.dispatch(request, **kwargs)
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/nap/publisher.py" in dispatch
      111.         return self.execute(handler)
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/nap/publisher.py" in execute
      118.                 object_id=self.object_id,
    File "/home/siecje/virtualenv/ccafe/local/lib/python2.7/site-packages/nap/publisher.py" in list_get_default
      335.         data['objects'] = serialiser.list_deflate(data['objects'], **serialiser_kwargs)
    
    Exception Type: TypeError at /lab/
    Exception Value: unbound method list_deflate() must be called with LabSerialiser instance as first argument (got QuerySet instance instead)
    
    class Lab(models.Model):
        title = models.CharField(max_length=255)
        duration = models.FloatField(help_text=_("Duration of Lab in Hours"), blank=True, null=True)
        description = models.TextField(null=True, blank=True)
    
    opened by Siecje 2
  • default_app_config leads to ImportError

    default_app_config leads to ImportError

    For some reason I had 'nap' in my INSTALLED_APPS and got this really confusing ImportError: No module named apps on Django 1.8. Removing default_app_config from nap/__init__.py fixed this, as does removing nap from the installed apps.

    I wonder if it's possible to provide a better error by default (probably Django's job), or to remove the app config. If not feel free to close this.

    opened by nkuttler 1
  • http.MethodNotAllowed() expects arguments always

    http.MethodNotAllowed() expects arguments always

    Not sure if this is a bug, but if you try to call http.MethodNotAllowed() without any parameters it 500s. Passing an arbitrary parameter fixes it.

    Eg this does not 500: http.MethodNotAllowed({'error':'error'})

    This does: http.MethodNotAllowed()

    Traceback;
    [09/Dec/2015 10:11:34] ERROR [django.request:256] Internal Server Error: /api/team/eject/
    Traceback (most recent call last):
      File "/Users/dre/Envs/gametraka_project/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/Users/dre/code/gametraka_project/apps/teams/rest_views.py", line 74, in team_eject
        return http.MethodNotAllowed()
    TypeError: __init__() takes at least 2 arguments (1 given)
    
    opened by limbera 1
  • Deleting successfully deletes instance but returns 500 (ObjectDeleteMixin)

    Deleting successfully deletes instance but returns 500 (ObjectDeleteMixin)

    When I issue a delete request to remove an instance, it is successfully deleted but the return code is 500. Looks like it's trying to get a field from the instance after it's been deleted?

    Mapper + Model + Traceback: http://dpaste.com/1VJMX4P

    opened by limbera 1
  • Published patterns() crashes if no api_name defined

    Published patterns() crashes if no api_name defined

    If no api_name is defined in Publisher-class exception happens:

    Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/home/jtiai/projects/katulupa.fi/keywinkki-light/winkki_services/urls.py", line 25, in <module>
        url(r'^license_logs/', include(ExportEntryListPublisher.patterns())),
      File "/home/jtiai/.virtualenvs/katulupa.fi/local/lib/python2.7/site-packages/nap/publisher.py", line 68, in patterns
        name = cls.api_name
    AttributeError: type object 'ExportEntryListPublisher' has no attribute 'api_name'
    
    opened by jtiai 1
  • Publisher uses hardcoded output format

    Publisher uses hardcoded output format

    Publisher uses hard-coded output which looks like

    {
        "meta": {},
        "objects": [{...},{...}]
    }
    

    It requires overriding both, get_page and list_get_default methods to produce different output. It should be much more straightforward

    enhancement 
    opened by jtiai 1
  • Provide a working example for (or document) validation in mappers

    Provide a working example for (or document) validation in mappers

    The examples in the docs about validation in mappers are not correct - at least, exceptions are raised when calling e.g. put_invalid in the way that is is shown in the docs. It is not clear what the errors parameter for put_invalid should actually be.

    This is the example code I'm referring to:

    [...]
             try:
                 data >> profile_mapper  # This is shorthand for _patch
             except ValidationError as e:
                 errors.update(dict(e))
    
             if errors:
                 return self.patch_invalid(errors)
    

    https://django-nap.readthedocs.io/en/latest/rest/index.html#example-updating-two-objects

    opened by m-thielen 0
Owner
Curtis Maloney
Curtis Maloney
Country-specific Django helpers, to use in Django Rest Framework

django-rest-localflavor Country-specific serializers fields, to Django Rest Framework Documentation (soon) The full documentation is at https://django

Gilson Filho 19 Aug 30, 2022
RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

Microsoft 1.8k Jan 4, 2023
Mlflow-rest-client - Python client for MLflow REST API

Python Client for MLflow Python client for MLflow REST API. Features: Minimal de

MTS 35 Dec 23, 2022
Authentication for Django Rest Framework

Dj-Rest-Auth Drop-in API endpoints for handling authentication securely in Django Rest Framework. Works especially well with SPAs (e.g React, Vue, Ang

Michael 1.1k Dec 28, 2022
Authentication Module for django rest auth

django-rest-knox Authentication Module for django rest auth Knox provides easy to use authentication for Django REST Framework The aim is to allow for

James McMahon 873 Dec 30, 2022
REST implementation of Django authentication system.

djoser REST implementation of Django authentication system. djoser library provides a set of Django Rest Framework views to handle basic actions such

Sunscrapers 2.2k Jan 1, 2023
A JSON Web Token authentication plugin for the Django REST Framework.

Simple JWT Abstract Simple JWT is a JSON Web Token authentication plugin for the Django REST Framework. For full documentation, visit django-rest-fram

Jazzband 3.3k Jan 4, 2023
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.

drf-yasg - Yet another Swagger generator Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with Django Res

Cristi Vîjdea 3k Jan 6, 2023
Django REST API with React BoilerPlate

This is a setup of Authentication and Registration Integrated with React.js inside the Django Templates for web apps

Faisal Nazik 91 Dec 30, 2022
Introduction to Django Rest Framework

Introduction to Django Rest Framework This is the repository of the video series Introduction to Django Rest Framework published on YouTube. It is a s

Simple is Better Than Complex 20 Jul 14, 2022
Scaffold django rest apis like a champion 🚀

scaffold django rest apis like a champion ??

Abdenasser Elidrissi 133 Jan 5, 2023
JSON:API support for Django REST framework

JSON:API and Django REST framework Overview JSON:API support for Django REST framework Documentation: https://django-rest-framework-json-api.readthedo

null 1k Dec 27, 2022
DRF-extensions is a collection of custom extensions for Django REST Framework

Django REST Framework extensions DRF-extensions is a collection of custom extensions for Django REST Framework Full documentation for project is avail

Gennady Chibisov 1.3k Dec 28, 2022
Generate Views, Serializers, and Urls for your Django Rest Framework application

DRF Generators Writing APIs can be boring and repetitive work. Don't write another CRUDdy view in Django Rest Framework. With DRF Generators, one simp

Tobin Brown 332 Dec 17, 2022
Swagger Documentation Generator for Django REST Framework: deprecated

Django REST Swagger: deprecated (2019-06-04) This project is no longer being maintained. Please consider drf-yasg as an alternative/successor. I haven

Marc Gibbons 2.6k Dec 23, 2022
Document Web APIs made with Django Rest Framework

DRF Docs Document Web APIs made with Django Rest Framework. View Demo Contributors Wanted: Do you like this project? Using it? Let's make it better! S

Manos Konstantinidis 626 Nov 20, 2022
Recursive Serialization for Django REST framework

djangorestframework-recursive Overview Recursive Serialization for Django REST framework This package provides a RecursiveField that enables you to se

null 336 Dec 28, 2022
Dropdown population implementation for Django REST Framework

drf-dropdown Dropdown population implementation for Django REST Framework Usage Add DropdownView to API URL # urls.py import dropdown urlpatterns = [

Preeti Yuankrathok 4 Dec 6, 2022