This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

django-simpleapi is an MIT Licensed django app, written in Python, for developers.

How many times have you wanted to create a simple JSON api in Django. I mean simple. There are great tools out their like * and * but sometimes you just want to send back some JSON.

This app makes it super simple to do that.

from simpleapi import api_handler

@api_handler
def get_some_yak(request):
    return {
        'yak': 'yummm'
    }

urlpatterns = patterns(
    '',
    url(r'^get/some/yak$', get_some_yak),
)
curl http://localhost:8000/get/some/yak

{
    "data": {
        "yak": "yummm"
    },
    "meta": {
        "code": 200
    }
}

Features

  • A Simple API for Django
  • Easy execption handling, creation
  • Easy addition to meta

Installation

To install Requests, simply:

$ pip install django-simpleapi

Documentation

This easyiest way to get started is to use the api_handler decorator.

from simpleapi import api_handler

@api_handler
def get_some_yak(request):
    return {
        'yak': 'yummm'
    }

Any view function that returns a dict object will work with this interface.

Next, often in APIs you need to fail for some reason. Validation, missing params, you name it. There is an easy way to make that happen SimpleHttpException

from simpleapi import api_handler, SimpleHttpException

@api_handler
def get_some_yak(request):
    required_param = request.GET.get('required_param')

    if required_param is None:
        raise SimpleHttpException("Missing required_param", 'missing-required-param', 400)

    return {
        'yak': 'yummm'
    }

Now when you request this view and forget to pass required_param you would see something like this.

curl http://localhost:8000/get/some/yak

{
    "meta": {
        "code": 400,
        "error_message": "Missing required_param",
        "error_slug": "missing-required-param"
    }
}

Not only will the HTTP Status code be in the meta response, it will also be the HTTP Code sent back. Error slug is helpfull in resolving exceptions progrmattically. It’s mucher easier then relying on string grepping to figure out what went wrong.

Finally, you might want to add you own information to the meta part of the envelope. This would helpfull for passing information like pagination information.

from simpleapi import api_handler

@api_handler
def get_some_yak(request):
    request.META['_simple_api_meta']['yak_count'] = 1

    return {
        'yak': 'yummm'
    }

The response would now look something like this.

curl http://localhost:8000/get/some/yak

{
    "data": {
        "yak": "yummm"
    },
    "meta": {
        "code": 200,
        "yak_counter": 1
    }
}
Release History

Release History

1.4.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-simpleapi-1.4.0.tar.gz (4.8 kB) Copy SHA256 Checksum SHA256 Source Feb 18, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting