Skip to main content

Quickest way to build powerful HTTP APIs in Python

Project description

kwikapi.django

Quickly build API services to expose functionality in Python. kwikapi.django was built by using the functionality of KwikAPI and Django web server.

Installation

$ pip3 install kwikapi[django]

Usage

Create a Django project

(Ref: https://docs.djangoproject.com/en/1.11/intro/tutorial01/)

$ django-admin startproject django_kwikapi

Create an app in Django

$ python3 manage.py startapp polls

Add your app name to settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
]

Make sure the contents of files be like this

/django_kwikapi/django_kwikapi/urls.py

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('polls.urls'))
]

/django_kwikapi/polls/urls.py

from django.conf.urls import url, include

from . import views
from kwikapi.django import RequestHandler

urlpatterns = [
    url(r'api/', RequestHandler(views.api).handle_request),
]

Example of django views

/django_kwikapi/polls/views.py

from django.http import HttpResponse
from kwikapi import API
from logging import Logger

class BaseCalc():
    def add(self, a: int, b: int) -> int:
        return a + b

    def subtract(self, a: int, b: int) -> int:
        return a - b

class StandardCalc():
    def multiply(self, a: int, b: int) -> int:
        return a * b

    def divide(self, a: int, b: int) -> float:
        return a / b

api = API(log=Logger, default_version='v1')
api.register(BaseCalc(), 'v1')
api.register(StandardCalc(), "v2")

Start Django

$ python3 manage.py makemigrations
$ python3 manage.py migrate
$ python3 manage.py runserver 8888

Make API request

$ curl "http://localhost:8888/api/v1/add?a=10&b=10"

To know how to use all features, please refer KwikAPI documentation https://github.com/deep-compute/kwikapi/blob/master/README.md

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

kwikapi-django-0.2.8.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

kwikapi_django-0.2.8-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file kwikapi-django-0.2.8.tar.gz.

File metadata

  • Download URL: kwikapi-django-0.2.8.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.6

File hashes

Hashes for kwikapi-django-0.2.8.tar.gz
Algorithm Hash digest
SHA256 416f29a84469f68d8384a27cb41cfdb55c79deac0f3c5de71718359569750a21
MD5 45cc61e2e31e9bf009ad30f41bdf7825
BLAKE2b-256 26cf52a56238213f8158e853e713236765393b38a85b316855a7f69a08880b7a

See more details on using hashes here.

File details

Details for the file kwikapi_django-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: kwikapi_django-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.6

File hashes

Hashes for kwikapi_django-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 507b2d1a48f06ce06080e81e4c2e5e46d47dfaeff53b5d92a3f376e0e62f2175
MD5 c90e5592d9b42534b34dc169a5c816cf
BLAKE2b-256 5dd38e177acd7aff58b42531c0d54323e14279ff97f89fae86cb02171212c8c9

See more details on using hashes here.

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