Create APIs in Django way
Project description
ArcStack Django API Framework
This is a simple yet extensible API framework for Django that you can create API endpoints Django way.
Check out Documentation for more info.
Sponsoring
Maintaining an open-source project requires attention and time. If you like this project and want it to be developed further, you might want to consider giving me a support.
If you are using ArcStack API in your project, please give me your feedback at me@gokhan.tr.
Installation
pip install arcstack-django-api
Usage
ArcStack Django API comes with CommonMiddleware enabled. This middleware
can convert your endpoint results to HttpResponse, handle exceptions and
check for logged in users.
Usage with class-based views:
from arcstack_api import Endpoint, APIError
class StatusOk(Endpoint):
# By default all defined enpoints do not require logged in user
# You can change this behavior with this class constant.
LOGIN_REQUIRED = True
def get(self, request, a: str | None = None):
if a == "something_invalid":
# This `dict` will be converted to `JSON` and `HttpResponse`
# will be generated
raise APIError(
{"error": "you have passed invalid argument"}
# The default status_code is `400` but it can be changed to
# anything you want.
status_code=480
)
# ArcStack API will serialize this to JSON and generate
# a `HttpResponse` for you.
return {"status": "OK"}
Usage with function views:
from arcstack_api import api_endpoint, Endpoint, APIError
@api_endpoint(login_required=True)
def statusOk(request, a: str | None = None):
if a == "something_invalid":
raise APIError(
{"error": "you have passed invalid argument"}
status_code=480
)
return {"status": "OK"}
In urls.py
from django.urls import path
from . import endpoints
urlpatterns = [
# For class-based views:
path("api", endpoints.StatusOk.as_endpoint()),
# For function views:
path("api", endpoints.statusOk),
]
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arcstack_django_api-0.2.1.tar.gz.
File metadata
- Download URL: arcstack_django_api-0.2.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.16 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e53786d5ff02ba033f2b075696a360a7309e0d21e60d611bfb5985d43598a6d0
|
|
| MD5 |
680995158220bcc7f17034e086330bad
|
|
| BLAKE2b-256 |
3366d9609efbfdbb173abeea7f841634cdab75555af758f83609c1788a7532fc
|
File details
Details for the file arcstack_django_api-0.2.1-py3-none-any.whl.
File metadata
- Download URL: arcstack_django_api-0.2.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.10.16 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baad75d410bb95bcc1b923aa7e7f28232fb470066583357651d9a9303bea7807
|
|
| MD5 |
11ee7f3a2f680a8c9e60424493d48684
|
|
| BLAKE2b-256 |
031afd35e071a49a4c15269a13ab1060856bf70504b0cfdffda815747925d24b
|