Name | django-microapi JSON |
Version |
1.2.1
JSON |
| download |
home_page | |
Summary | A tiny library to make writing CBV-based APIs easier in Django. |
upload_time | 2024-01-15 20:59:29 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.7 |
license | BSD-3-Clause |
keywords |
django
json
api
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# django-microapi
[](https://django-microapi.readthedocs.io/en/latest/?badge=latest)
A tiny library to make writing CBV-based APIs easier in Django.
Essentially, this just provides some sugar on top of the plain old `django.views.generic.base.View` class, all with the intent of making handling JSON APIs easier (without the need for a full framework).
## Usage
```python
from django.contrib.auth.decorators import login_required
# We pull in two useful classes from `microapi`.
from microapi import ApiView, ModelSerializer
from .models import BlogPost
# Inherit from the `ApiView` class...
class BlogPostView(ApiView):
# ...then define `get`/`post`/`put`/`delete`/`patch` methods on the
# subclass.
# For example, we'll provide a list view on `get`.
def get(self, request):
posts = BlogPost.objects.all().order_by("-created")
# The `render` method automatically creates a JSON response from
# the provided data.
return self.render({
"success": True,
"posts": self.serialize_many(posts),
})
# And handle creating a new blog post on `post`.
@login_required
def post(self, request):
# Read the JSON
data = self.read_json(request)
# TODO: Validate the data here.
# Use the included `ModelSerializer` to load the user-provided data
# into a new `BlogPost`.
post = self.serializer.from_dict(BlogPost(), data)
# Don't forget to save!
post.save()
return self.render({
"success": True,
"post": self.serialize(post),
})
```
## Installation
```bash
$ pip install django-microapi
```
## Rationale
There are a lot of API frameworks out there (hell, I [built](https://tastypieapi.org/) [two](https://github.com/toastdriven/restless) of them). But for many tasks, they're either [overkill](https://en.wikipedia.org/wiki/HATEOAS) or just too opinionated.
So `django-microapi` is kind of the antithesis to those. With the exception of a tiny extension to `View` for nicer errors, it doesn't call **ANYTHING** automatically. Other than being JSON-based, it doesn't have opinions on serialization, or validation, or URL structures.
You write the endpoints you want, and `microapi` brings some conveniences to the table to make writing that endpoint as simple as possible _without_ assumptions.
I've long had a place in my heart for the simplicity of Django's function-based views, as well as the conveniences of `django.shortcuts`. `microapi` tries to channel that love/simplicity.
## API Docs
https://django-microapi.rtfd.io/
## Testing
To run the tests, you'll need both [Pipenv](https://pipenv.pypa.io/en/latest/), and [Just](https://just.systems/) installed.
```shell
$ just test
```
## License
New BSD
Raw data
{
"_id": null,
"home_page": "",
"name": "django-microapi",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "django,json,api",
"author": "",
"author_email": "Daniel Lindsley <daniel@toastdriven.com>",
"download_url": "https://files.pythonhosted.org/packages/06/c8/95be58162f0e0d5af1aaf9abaddf8b3e67bcdf99ba894dad3683e74bd148/django-microapi-1.2.1.tar.gz",
"platform": null,
"description": "# django-microapi\n\n[](https://django-microapi.readthedocs.io/en/latest/?badge=latest)\n\nA tiny library to make writing CBV-based APIs easier in Django.\n\nEssentially, this just provides some sugar on top of the plain old `django.views.generic.base.View` class, all with the intent of making handling JSON APIs easier (without the need for a full framework).\n\n\n## Usage\n\n```python\nfrom django.contrib.auth.decorators import login_required\n\n# We pull in two useful classes from `microapi`.\nfrom microapi import ApiView, ModelSerializer\n\nfrom .models import BlogPost\n\n\n# Inherit from the `ApiView` class...\nclass BlogPostView(ApiView):\n # ...then define `get`/`post`/`put`/`delete`/`patch` methods on the\n # subclass.\n\n # For example, we'll provide a list view on `get`.\n def get(self, request):\n posts = BlogPost.objects.all().order_by(\"-created\")\n\n # The `render` method automatically creates a JSON response from\n # the provided data.\n return self.render({\n \"success\": True,\n \"posts\": self.serialize_many(posts),\n })\n\n # And handle creating a new blog post on `post`.\n @login_required\n def post(self, request):\n # Read the JSON\n data = self.read_json(request)\n\n # TODO: Validate the data here.\n\n # Use the included `ModelSerializer` to load the user-provided data\n # into a new `BlogPost`.\n post = self.serializer.from_dict(BlogPost(), data)\n # Don't forget to save!\n post.save()\n\n return self.render({\n \"success\": True,\n \"post\": self.serialize(post),\n })\n```\n\n\n## Installation\n\n```bash\n$ pip install django-microapi\n```\n\n\n## Rationale\n\nThere are a lot of API frameworks out there (hell, I [built](https://tastypieapi.org/) [two](https://github.com/toastdriven/restless) of them). But for many tasks, they're either [overkill](https://en.wikipedia.org/wiki/HATEOAS) or just too opinionated.\n\nSo `django-microapi` is kind of the antithesis to those. With the exception of a tiny extension to `View` for nicer errors, it doesn't call **ANYTHING** automatically. Other than being JSON-based, it doesn't have opinions on serialization, or validation, or URL structures.\n\nYou write the endpoints you want, and `microapi` brings some conveniences to the table to make writing that endpoint as simple as possible _without_ assumptions.\n\nI've long had a place in my heart for the simplicity of Django's function-based views, as well as the conveniences of `django.shortcuts`. `microapi` tries to channel that love/simplicity.\n\n\n## API Docs\n\nhttps://django-microapi.rtfd.io/\n\n\n## Testing\n\nTo run the tests, you'll need both [Pipenv](https://pipenv.pypa.io/en/latest/), and [Just](https://just.systems/) installed.\n\n```shell\n$ just test\n```\n\n\n## License\n\nNew BSD\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "A tiny library to make writing CBV-based APIs easier in Django.",
"version": "1.2.1",
"project_urls": {
"Homepage": "https://github.com/toastdriven/django-microapi",
"Issues": "https://github.com/toastdriven/django-microapi/issues",
"Repository": "https://github.com/toastdriven/django-microapi.git"
},
"split_keywords": [
"django",
"json",
"api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5eb9cd78b00dd7336e1b5a3040e19c68d110d55b533433be9d6f98c0cdda788",
"md5": "fe6984995b93c5a3d6e8d0f754b962aa",
"sha256": "2ec0cec3987f62caae8d971c9a849b2d92bb86b178e1653c3b671cab6273b6b1"
},
"downloads": -1,
"filename": "django_microapi-1.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe6984995b93c5a3d6e8d0f754b962aa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 11198,
"upload_time": "2024-01-15T20:59:27",
"upload_time_iso_8601": "2024-01-15T20:59:27.804788Z",
"url": "https://files.pythonhosted.org/packages/b5/eb/9cd78b00dd7336e1b5a3040e19c68d110d55b533433be9d6f98c0cdda788/django_microapi-1.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "06c895be58162f0e0d5af1aaf9abaddf8b3e67bcdf99ba894dad3683e74bd148",
"md5": "a66efebdf25b24224797f396a6df88fc",
"sha256": "5a51cc5ecfc9dd71c88d46635f1fcb8c6454cf06312c01f3807a27b11b826b4f"
},
"downloads": -1,
"filename": "django-microapi-1.2.1.tar.gz",
"has_sig": false,
"md5_digest": "a66efebdf25b24224797f396a6df88fc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 9599,
"upload_time": "2024-01-15T20:59:29",
"upload_time_iso_8601": "2024-01-15T20:59:29.363492Z",
"url": "https://files.pythonhosted.org/packages/06/c8/95be58162f0e0d5af1aaf9abaddf8b3e67bcdf99ba894dad3683e74bd148/django-microapi-1.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-15 20:59:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "toastdriven",
"github_project": "django-microapi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-microapi"
}