{ "info": { "author": "Benoit Chesneau", "author_email": "benoitc@e-engura.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Application Frameworks" ], "description": "dj-webmachine\n-------------\n\ndj-webmachine is an application layer that adds HTTP semantic awareness on \ntop of Django and provides a simple and clean way to connect that to\nyour applications' behavior. dj-webmachine also offers you the\npossibility to build simple API based on your model and the tools to\ncreate automatically docs and clients from it (work in progress).\n\n\n\nInstall\n+++++++\n\nMake sure that you have a working Python_ 2.x >=2.5 installed and Django_ >= 1.1.\n\n\nWith pip\n~~~~~~~~\n\n::\n \n $ pip install dj-webmachine\n\nFrom source\n~~~~~~~~~~~\n\nGet the dj-webmachine code::\n\n $ git clone https://github.com/benoitc/dj-webmachine.git\n $ cd dj-webmachine\n\nOr using a tarbal::\n\n $ wget http://github.com/benoitc/dj-webmachine/tarball/master -o dj-webmachine.tar.gz\n $ tar xvzf dj-webmachine.tar.gz\n $ cd dj-webmachine-$HASH/\n\nand install::\n\n $ sudo python setup.py install\n\n\ndj-webmachine in 5 minutes\n++++++++++++++++++++++++++\n\nWe will quickly create an Hello world accepting HTML and JSON.\n\n::\n\n $ django-admin startproject helloworld\n $ cd helloworld\n $ python manage.py startapp hello\n\nIn the hello folder create a file named ``resources.py``::\n\n import json\n from webmachine import Resource\n \n class Hello(Resource):\n\n def content_types_provided(self, req, resp):\n \"\"\"\" define the content type we render accoridng the Accept\n header.\n \"\"\"\n return ( \n (\"\", self.to_html),\n (\"application/json\", self.to_json)\n )\n\n def to_html(self, req, resp):\n return \"
Hello world!\\n\"\n \n def to_json(self, req, resp):\n return \"%s\\n\" % json.dumps({\"message\": \"hello world!\", \"ok\": True})\n \nAdd **dj-webmachine** and your hello app to ``INSTALLED_APPS`` in your\nsettings::\n\n INSTALLED_APPS = (\n ...\n 'webmachine',\n 'helloworld.hello'\n )\n\nPut your the Hello resource in your ``urls.py``::\n\n from django.conf.urls.defaults import *\n\n from helloworld.hello.resource import Hello\n\n urlpatterns = patterns('',\n (r'^$', Hello()),\n )\n\nLaunch your application::\n\n $ python manage.py runserver\n\nTake a look! Point a web browser at http://localhost:8000/\n\nOr with curl::\n\n $ curl http://127.0.0.1:8000\n Hello world!\n\n $ curl http://127.0.0.1:8000 -H \"Accept: application/json\"\n {\"message\": \"hello world!\", \"ok\": true} \n\n\n \nThe first line ask the hello page as html while the second using the\nsame url ask for JSON. \n\nTo learn how to do more interresting things, checkout `some examples