{ "info": { "author": "Olivier Meunier", "author_email": "olivier@neokraft.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Utilities" ], "description": "Introduction\n============\n\nDjango Restlayer is a very simple to use toolkit to create RESTful APIs for your Django projects\nor apps.\n\nFeatures\n========\n\n- Allows you to respect HTTP methods and headers within your application.\n- Class based resources.\n- Simple to code.\n- Form validation in case you need it.\n\nInstallation\n============\n\n- For Django 1.4: ``pip install django-restlayer==0.8.5``\n- For Django 1.5+: ``pip install django-restlayer``\n\nConfiguration\n=============\n\nDjango Restlayer doesn't need any configuration nor any app in ``INSTALLED_APPS`` settings.\n\nSimple example\n==============\n\nurls.py::\n\n from django.conf.urls import patterns, url\n\n urlpatterns = patterns('',\n url(r'^$', 'myapp.resources.simple', name='simple'),\n )\n\nmyapp/resources.py::\n\n from restlayer import Resource, Response\n\n # Our resource class\n class SimpleResponse(Response):\n def response_get(self, request):\n return ['foo', 'bar']\n\n # Resource (a callable object or a view if you prefer)\n simple = Resource(SimpleResponse)\n\nThat's it. Now, query your development server ::\n\n curl -s -v -H \"accept:application/json\" http://localhost:8000/\n\n > GET /api/ HTTP/1.1\n > User-Agent: curl/7.33.0\n > Host: localhost\n > accept:application/json\n >\n < HTTP/1.1 200 OK\n < Server: nginx/1.4.3\n < Date: Thu, 28 Nov 2013 14:34:15 GMT\n < Content-Type: application/json; charset=UTF-8\n < Transfer-Encoding: chunked\n < Connection: keep-alive\n < Vary: Accept-Language, Cookie\n < Content-Language: en\n <\n [\n \"foo\",\n \"bar\"\n ]\n\nUsage\n=====\n\nResponse class\n--------------\n\nAll your responses should inherit ``restlayer.Response`` class. Then, add methods named\n``response_VERB`` where ``VERB`` is an HTTP verb. To handle GET responses, you need to create\na ``response_get`` method, for POST, ``response_post``. Each ``response_VERB`` method acts as a view\nwith needed arguments. A basic example:\n\n::\n\n from restlayer import Response\n\n class SimpleResponse(Response):\n def response_get(self, request, my_id):\n # This method will match a URL pattern with \"my_id\"\n return \"foo\"\n\nPredefined response methods\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThere are two predefined response methods:\n\n- ``response_options`` returns an empty 204 response with ``Allow`` header.\n- ``response_head`` calls ``response_get`` if any and returns it without body.\n\nSerializers\n~~~~~~~~~~~\n\nYou can set ``serializers`` and ``deserializers`` properties. They set how data are going to be\nserialized (out) or unserialized (in). In this example, we add a silly serializer for text/plain:\n\n::\n\n class SimpleResponse(Response):\n serializers = Response.serializers + (\n ('text/plain', lambda x: return str(x))\n )\n\nWell, that won't work very well but you have the idea. ``serializers`` is a list of tuples of mime\ntypes and callables getting data as only parameter. ``deserializers`` is the same thing for accepted\ndata types (callable takes ``request`` as only argument).\n\nDefault formats are:\n\n- ``serializers``\n - application/json\n - application/xml\n - application/python-pickle\n- ``deserializers``\n - application/x-www-form-urlencoded\n - multipart/form-data\n - application/json\n\nResponses are valid HttpResponse objects\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n``restlayer.Response`` instances are valid ``django.http.HttpResponse`` objects. Thus you can:\n\n- Add any header you want to your response setting ``self['my-header']`` before returning data;\n- Change status code with ``self.status_code``;\n- Return ``self`` if you need to set a specific response content without using serializers.\n\nResource\n--------\n\nYour response class should be wrapped within a ``restlayer.Resource`` class. The resulting instance\nis a callable acting like a classic view. You can extend this class to create your own resource.\nSimply override ``__call__`` method.\n\n::\n\n from restlayer import Resource\n\n class SillyResource(Resource):\n def __call__(self, request, *args, **kwargs):\n rsp = super(SillyResource, self).__call__(request, *args, **kwargs)\n rsp.status_code = 401\n rsp['Content-Type'] = 'text/plain'\n return rsp\n\nResponses for Django models\n---------------------------\n\nIf you are working with Django models, you can use ``restlayer.ModelResponse``. Using this parent\nclass for your responses, you can return model instance or queryset. Here is a simple example:\n\n::\n\n from django.contrib.auth.models import User\n from restlayer import ModelResponse\n\n class SimpleResponse(ModelResponse):\n fields = ('id', 'name', 'firstname', 'email')\n\n def response_get(self, request):\n return User.objects.all()\n\nThat's it! Using the ``fields`` property, you set the fields you want to return in the response.\n\nYou can add custom methods to create a specific response field. This method takes two parameters:\n``\u00ecnstance`` and ``request``. Example:\n\n::\n\n from django.contrib.auth.models import User\n from restlayer import ModelResponse\n\n class SimpleResponse(ModelResponse):\n fields = ('id', 'name', 'firstname', 'email', 'other_field')\n\n def other_field(self, instance, request):\n return instance.name.capitalize()\n\n def response_get(self, request):\n return User.objects.all()\n\nURLs\n----\n\nYou'll often need to create a ``resource_uri`` field to point to another resource in your API.\nResponse class provides two methods to create absolute (with FQDN) URLs:\n\n- ``_build_absolute_uri(self, request, [location])`` only calling ``request.build_absolute_uri(location)``\n but you can override it if you need.\n- ``reverse(self, request, view, [args, kwargs])`` acts as ``django.core.urlresolvers.reverse`` but\n returns an absolute URL.\n\nPagination\n----------\n\nYou might want to paginate your responses. Restlayer Response class provides a simple method for\nthis task: ``paginate(self, request, object_list, [limit])`` which is a simple wrapper around\n``django.core.paginator.Paginator``. Resulting response will contain the following headers:\n\n- X-Pages-Objects\n- X-Pages-Count\n- X-Pages-Current\n- X-Pages-Next (if next page exists)\n- X-Pages-Next-URI (if next page exists)\n- X-Pages-Prev (if previous page exists)\n- X-Pages-Prev-URI (if previous page exists)\n\nUse the source\n==============\n\nI admit this documentation is a bit rough. Don't hesitate to read the source code, there's no\nhidden rocket science, only some basic python code :)\n\nLicense\n=======\n\nDjango Restlayer is released under the MIT license. See the LICENSE\nfile for the complete license.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/olivier-m/django-restlayer", "keywords": null, "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "django-restlayer", "package_url": "https://pypi.org/project/django-restlayer/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-restlayer/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/olivier-m/django-restlayer" }, "release_url": "https://pypi.org/project/django-restlayer/0.9.0/", "requires_dist": null, "requires_python": null, "summary": "HTTP REST toolkit for Django", "version": "0.9.0" }, "last_serial": 939700, "releases": { "0.8.5": [ { "comment_text": "", "digests": { "md5": "bc77445a51ab0a5d7ede8e5986ce6fb1", "sha256": "5e76bce00a1bc790a7f6e80df0fc8533c4aa8659f552700ab736d974e4e9b1d1" }, "downloads": -1, "filename": "django-restlayer-0.8.5.tar.gz", "has_sig": false, "md5_digest": "bc77445a51ab0a5d7ede8e5986ce6fb1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8439, "upload_time": "2013-12-08T13:05:47", "url": "https://files.pythonhosted.org/packages/db/e1/7cf0f37cc24087c4ef7d25b8f30cdaf04c23af02823da15d05d48c765fc3/django-restlayer-0.8.5.tar.gz" } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "54111be62d9fdbf7d61daaf370e22736", "sha256": "9fe7b245f0b05b68164f9c67334464f4a2c40de2f3fd262051d25a38d0c30db5" }, "downloads": -1, "filename": "django-restlayer-0.9.0.tar.gz", "has_sig": false, "md5_digest": "54111be62d9fdbf7d61daaf370e22736", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8617, "upload_time": "2013-12-08T13:42:45", "url": "https://files.pythonhosted.org/packages/14/01/27700dc3417eaedad3b6798ba885dc9db33df92511b82f68563a3fb80e53/django-restlayer-0.9.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "54111be62d9fdbf7d61daaf370e22736", "sha256": "9fe7b245f0b05b68164f9c67334464f4a2c40de2f3fd262051d25a38d0c30db5" }, "downloads": -1, "filename": "django-restlayer-0.9.0.tar.gz", "has_sig": false, "md5_digest": "54111be62d9fdbf7d61daaf370e22736", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8617, "upload_time": "2013-12-08T13:42:45", "url": "https://files.pythonhosted.org/packages/14/01/27700dc3417eaedad3b6798ba885dc9db33df92511b82f68563a3fb80e53/django-restlayer-0.9.0.tar.gz" } ] }