Metadata-Version: 2.4
Name: unrest_api
Version: 0.4.0
Summary: Lightweight Django utilities for JSON APIs: schema-driven form views, auth endpoints, user settings, and middleware.
Author-email: Chris Cauley <casscauley@incentfit.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/chriscauley/unrest-server
Project-URL: Repository, https://github.com/chriscauley/unrest-server
Project-URL: Changelog, https://github.com/chriscauley/unrest-server/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/chriscauley/unrest-server/issues
Keywords: django,rest,api,forms,json
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django>=5.2
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-django; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Dynamic: license-file

# unrest_api

Lightweight Django utilities for building JSON APIs - schema-driven form views, auth endpoints, user-settings scaffolding, and helpful middleware.

## Install

```bash
pip install unrest_api
```

Add to `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    # ...
    "unrest_api",
]
```

## Features

- **`unrest_api.schema.schema_form`** — turn a `ModelForm` into a JSON CRUD endpoint (GET schema, POST create, PUT partial update, DELETE).
- **`unrest_api.schema.UnrestForm`** — `ModelForm` base that exposes `self.request` so `__init__`, `clean`, and `save` can scope querysets and defaults to the current user.
- **`unrest_api.urls`** — drop-in auth routes (`login`, `logout`, `register`, `settings`).
- **`unrest_api.models.AbstractUserSettings`** — abstract base providing `timezone` and `theme` plus the `OneToOneField` to `AUTH_USER_MODEL` (`related_name='settings'`).
- **`unrest_api.middleware.Json404Middleware`** — converts `Http404` raised under an API prefix into `JsonResponse({'error': ...}, status=404)`.

## Quick start

```python
# urls.py
from django.urls import include, path

urlpatterns = [
    path("api/auth/", include("unrest_api.urls")),
]
```

```python
# forms.py
from unrest_api.schema import UnrestForm, register
from .models import Widget

@register
class WidgetForm(UnrestForm):
    class Meta:
        model = Widget
        fields = ["name", "color"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # self.request is available here
```

## Settings

| Setting | Default | Description |
| --- | --- | --- |
| `UNREST_USER_SETTINGS_FORM` | `None` | Dotted path to a `ModelForm` for project-specific fields exposed by the unified `settings` endpoint. |
| `UNREST_JSON_404_PREFIX` | `"/api/"` | URL prefix under which `Json404Middleware` converts `Http404` to JSON. |

## Compatibility

- Python 3.11+
- Django 5.2+

## Changelog

See [CHANGELOG.md](CHANGELOG.md).

## License

MIT
