Skip to content

Commit

Permalink
Merge pull request #2 from RamanjaneyuluIdavalapati/master
Browse files Browse the repository at this point in the history
README improved
  • Loading branch information
Ram Idavalapati authored Feb 7, 2018
2 parents 2fb9b5c + a2d4734 commit 811443d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ script:
- echo "No tests as of now"
deploy:
- provider: releases
skip_cleanup: true
api_key:
secure: szU2C7KG3GzWO6x5RleHRf+/OpKvZWpN9Z+JPYb0xr+oSCQfms5/kMG8tTBUxjm5exv6xRsnknAa0vL+DqyeNEo8bPBYt3ZoDbB9pTqZhYuKSqDQnAP9N7xrmaXK7AVtuY07zDVToI6M0pWaqn+7A5YG0c9lqt3EuaCbSosqShzoDEZvO9bY1q4tsmjrP7hC28phsOuXCRzBBSabXEueyNeJInDTVFjfxp+yD1du3zIC1Qy4hi1rurTROSogKVWaChVcR9JJdAdawG/5J4QULtuma8fBvo2GhrJSH6ofTsLI1LXo64IixXqhb+FoAbABMjDkukjOXfOgiovGeay5n1PFuenFvQY3T3OscGJId16HeQPJ8BPd6U1k0b57Ij9Fl2nraUSIVpoC3tpBfyhMfXyF08ZEfXIJJwQl1BU96EZXt7PpgY7Mh9MwUnKh6SZ6E9ykwp1jVQ+YSS47u5nWpdAr6DYkjrCfwxw9hOWqH1tgyiSNw1u0xpA7qWUAl8JrEQrrq1EG9buGrH3aeF0p4eyTg38IdqQGhXNWLVJzo4U+QdVT930hDE6CCwhvc5otFiBKqED3ZAidAOJOq4ECZLPOGc8YIvd/4LXZTsaZEfQ1ovAqJnxTOvS5TnarAGI4CO8OvyqTN3nRdzrcMcYkdK5xyoG/jqHPD2jB3H/5Sls=
file:
Expand All @@ -16,8 +17,8 @@ deploy:
- kwikapi/__init__.py
- kwikapi/django/__init__.py
- kwikapi/django/kwikapi_django.py
name: kwikapi.django-0.0.1
tag_name: 0.0.1
name: kwikapi.django-0.1
tag_name: 0.1
on:
repo: deep-compute/kwikapi.django
- provider: pypi
Expand Down
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
# Use kwikapi in Django
# 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

## Install kwikapi for Django
```bash
$ pip install kwikapi[django]
```

## Create a Django project (Ref: https://docs.djangoproject.com/en/1.9/intro/tutorial01/)
## Usage

### Create a Django project

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

```bash
$ django-admin startproject django_kwikapi
```

## Create an app in Django
### Create an app in Django

```bash
$ python manage.py startapp polls
``
```

### Add your app name to settings.py

#### Add your app name to settings.py
```python
INSTALLED_APPS = [
'django.contrib.admin',
Expand All @@ -27,7 +37,10 @@ INSTALLED_APPS = [
'polls',
]
```
## /django_kwikapi/django_kwikapi/urls.py
### 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
Expand All @@ -38,52 +51,59 @@ urlpatterns = [
]
```

## /django_kwikapi/polls/urls.py
/django_kwikapi/polls/urls.py

```python
from django.conf.urls import url, include

from . import views
from kwikapi.django import RequestHandler
from kwikapi_django import RequestHandler

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

## /django_kwikapi/polls/views.py
### 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:
def add(self, request, a: int, b: int):
return a + b

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

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

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

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

## Start Django
### Start Django

```bash
$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py runserver 8888
```

## Make API request
### Make API request

```bash
$ curl http://localhost:8888/api/v1/add?a=10&b=10
$ curl http://localhost:8888/api/v2/divide?a=10&b=10
$ 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
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from setuptools import setup, find_packages

version = '0.0.1'
version = '0.1'
setup(
name="kwikapi_django",
name="kwikapi-django",
version=version,
packages=find_packages("."),
package_dir={'kwikapi_django': 'django'},
Expand All @@ -14,7 +14,7 @@
author='Deep Compute, LLC',
author_email='[email protected]',
install_requires=[
'django==1.9',
'django==1.11',
],
classifiers=[
'Environment :: Web Environment',
Expand Down

0 comments on commit 811443d

Please sign in to comment.