Skip to main content

A non-intrusive component that can help you quickly create APIs.

Project description

Language: English | Chinese

Django Simple API

A non-intrusive component that can help you quickly create APIs.

Quick Start

Install

Download and install from github:

pip install django-simple-api

Configure

Add django-simple-api to your INSTALLED_APPS in settings:

INSTALLED_APPS = [
    ...,
    "django_simple_api",
]

Register the middleware to your MIDDLEWARE in settings:

MIDDLEWARE = [
    ...,
    "django_simple_api.middleware.SimpleApiMiddleware",
]

Add the url of django-simple-api to your urls.py:

# urls.py

from django.urls import include, path
from django.conf import settings

# Your urls
urlpatterns = [
    ...
]

# Simple API urls, should only run in a test environment.
if settings.DEBUG:
    urlpatterns += [
        # generate documentation
        path("docs/", include("django_simple_api.urls"))
    ]

Complete the first example

Define your url:

# your urls.py

from django.urls import path
from yourviews import JustTest

urlpatterns = [
    ...,
    path("/path/<int:id>/", JustTest.as_view()),
]

Define your view:

# your views.py

from django.views import View
from django.http.response import HttpResponse

from django_simple_api import Query


class JustTest(View):
    def get(self, request, id: int = Query()):
        return HttpResponse(id)

⚠️ To generate the document, you must declare the parameters according to the rules of Simple API (like the example above).

Click Declare parameters to see how to declare parameters.

Access interface document

After the above configuration, you can start your server and access the interface documentation now.

If your service is running locally, you can visit http://127.0.0.1:8000/docs/ to view your documentation.

More

For more tutorials, see Django Simple API.

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

django-simple-api-0.2.2.tar.gz (676.5 kB view hashes)

Uploaded Source

Built Distribution

django_simple_api-0.2.2-py3-none-any.whl (684.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page