1- # Use kwikapi in Django
1+ # kwikapi.django
2+
3+ Quickly build API services to expose functionality in Python. ` kwikapi.django ` was built by using the functionality of KwikAPI and Django web server.
4+
5+ ## Installation
26
3- ## Install kwikapi for Django
47``` bash
58$ pip install kwikapi[django]
69```
710
8- ## Create a Django project (Ref: https://docs.djangoproject.com/en/1.9/intro/tutorial01/)
11+ ## Usage
12+
13+ ### Create a Django project
14+
15+ (Ref: https://docs.djangoproject.com/en/1.9/intro/tutorial01/ )
16+
917``` bash
1018$ django-admin startproject django_kwikapi
1119```
1220
13- ## Create an app in Django
21+ ### Create an app in Django
22+
1423``` bash
1524$ python manage.py startapp polls
16- ` `
25+ ```
26+
27+ ### Add your app name to settings.py
1728
18- # ### Add your app name to settings.py
1929``` python
2030INSTALLED_APPS = [
2131 ' django.contrib.admin' ,
@@ -27,7 +37,10 @@ INSTALLED_APPS = [
2737 ' polls' ,
2838]
2939```
30- # # /django_kwikapi/django_kwikapi/urls.py
40+ ### Make sure the contents of files be like this
41+
42+ /django_kwikapi/django_kwikapi/urls.py
43+
3144``` python
3245from django.conf.urls import url, include
3346from django.contrib import admin
@@ -38,52 +51,59 @@ urlpatterns = [
3851]
3952```
4053
41- # # /django_kwikapi/polls/urls.py
54+ /django_kwikapi/polls/urls.py
55+
4256``` python
4357from django.conf.urls import url, include
4458
4559from . import views
46- from kwikapi.django import RequestHandler
60+ from kwikapi_django import RequestHandler
4761
4862urlpatterns = [
4963 url(r ' api/' , RequestHandler(views.api).handle_request),
5064]
5165```
5266
53- # # /django_kwikapi/polls/views.py
67+ ### Example of django views
68+
69+ /django_kwikapi/polls/views.py
70+
5471``` python
5572from django.http import HttpResponse
5673from kwikapi import API
5774from logging import Logger
5875
5976class BaseCalc ():
60- def add(self, a: int, b: int) - > int :
77+ def add (self , request , a : int , b : int ):
6178 return a + b
6279
63- def subtract(self, a: int, b: int) - > int :
80+ def subtract (self , request , a : int , b : int ):
6481 return a - b
6582
6683class StandardCalc ():
67- def multiply(self, a: int, b: int) - > int :
84+ def multiply (self , request , a : int , b : int ):
6885 return a * b
6986
70- def divide(self, a: int, b: int) - > int :
87+ def divide (self , request , a : int , b : int ):
7188 return a / b
7289
7390api = API(Logger, default_version = ' v1' )
7491api.register(BaseCalc(), ' v1' )
7592api.register(StandardCalc(), " v2" )
7693```
7794
78- # # Start Django
95+ ### Start Django
96+
7997``` bash
8098$ python manage.py makemigrations
8199$ python manage.py migrate
82100$ python manage.py runserver 8888
83101```
84102
85- # # Make API request
103+ ### Make API request
104+
86105``` bash
87- $ curl http://localhost:8888/api/v1/add? a=10& b=10
88- $ curl http://localhost:8888/api/v2/divide? a=10& b=10
106+ $ curl " http://localhost:8888/api/v1/add?a=10&b=10"
89107```
108+
109+ > To know how to use all features, please refer KwikAPI documentation https://github.com/deep-compute/kwikapi/blob/master/README.md
0 commit comments