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
```bash
$ pip3 install kwikapi[django]
```
## Usage
### Create a Django project
(Ref: https://docs.djangoproject.com/en/1.11/intro/tutorial01/)
```bash
$ django-admin startproject django_kwikapi
```
### Create an app in Django
```bash
$ python3 manage.py startapp polls
```
### Add your app name to settings.py
```python
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
```python
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
```python
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
```python
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(Logger, default_version='v1')
api.register(BaseCalc(), 'v1')
api.register(StandardCalc(), "v2")
```
### Start Django
```bash
$ python3 manage.py makemigrations
$ python3 manage.py migrate
$ python3 manage.py runserver 8888
```
### Make API request
```bash
$ 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
Quickly build API services to expose functionality in Python. `kwikapi.django` was built by using the functionality of KwikAPI and Django web server.
## Installation
```bash
$ pip3 install kwikapi[django]
```
## Usage
### Create a Django project
(Ref: https://docs.djangoproject.com/en/1.11/intro/tutorial01/)
```bash
$ django-admin startproject django_kwikapi
```
### Create an app in Django
```bash
$ python3 manage.py startapp polls
```
### Add your app name to settings.py
```python
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
```python
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
```python
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
```python
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(Logger, default_version='v1')
api.register(BaseCalc(), 'v1')
api.register(StandardCalc(), "v2")
```
### Start Django
```bash
$ python3 manage.py makemigrations
$ python3 manage.py migrate
$ python3 manage.py runserver 8888
```
### Make API request
```bash
$ 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
Release history Release notifications | RSS feed
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.5.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for kwikapi_django-0.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a10863fcb76bdc7932c3fe66b573312283f61c1f923e0784cef23b423533d8a |
|
MD5 | acdf510a675e7f925c1038360abd0e5b |
|
BLAKE2b-256 | c397c11e4f4ece3045defe6a22f5e93886028192fe87887ac12f2c6a8b867e2f |