{"id":13937083,"url":"https://github.com/5monkeys/django-formapi","last_synced_at":"2025-04-14T01:15:21.715Z","repository":{"id":7056969,"uuid":"8338954","full_name":"5monkeys/django-formapi","owner":"5monkeys","description":"Django API creation with signed requests utilizing forms for validation.","archived":false,"fork":false,"pushed_at":"2022-04-12T13:00:55.000Z","size":158,"stargazers_count":35,"open_issues_count":4,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T15:21:18.506Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/5monkeys.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-21T16:24:32.000Z","updated_at":"2024-04-29T13:59:46.000Z","dependencies_parsed_at":"2022-09-03T20:00:13.496Z","dependency_job_id":null,"html_url":"https://github.com/5monkeys/django-formapi","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fdjango-formapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fdjango-formapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fdjango-formapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5monkeys%2Fdjango-formapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/5monkeys","download_url":"https://codeload.github.com/5monkeys/django-formapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782270,"owners_count":21160717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-07T23:03:16.147Z","updated_at":"2025-04-14T01:15:21.695Z","avatar_url":"https://github.com/5monkeys.png","language":"Python","readme":"django-formapi\n==============\n\nCreate JSON API:s with HMAC authentication and Django form-validation.\n\n.. image:: https://travis-ci.com/5monkeys/django-formapi.svg?branch=master\n    :target: http://travis-ci.com/5monkeys/django-formapi\n.. image:: https://coveralls.io/repos/github/5monkeys/django-formapi/badge.svg?branch=master\n    :target: https://coveralls.io/github/5monkeys/django-formapi?branch=master\n.. image:: https://badge.fury.io/py/django-formapi.svg\n    :target: https://badge.fury.io/py/django-formapi\n.. image:: https://img.shields.io/pypi/l/django-formapi.svg\n    :target: https://pypi.python.org/pypi/django-formapi\n.. image:: https://img.shields.io/pypi/wheel/django-formapi.svg\n    :target: https://pypi.python.org/pypi/django-formapi\n.. image:: https://img.shields.io/pypi/pyversions/django-formapi.svg\n    :target: https://pypi.python.org/pypi/django-formapi\n.. image:: https://img.shields.io/pypi/dm/django-formapi.svg\n    :target: https://pypi.python.org/pypi/django-formapi\n\n\nVersion compatibility\n---------------------\n\nSee Travis-CI page for actual test results:\nhttps://travis-ci.com/5monkeys/django-formapi\n\n======  ===\nDjango  3.6\n======  ===\n 3.2    Yes\n======  ===\n\n\nInstallation\n------------\n\nInstall django-formapi in your python environment\n\n.. code:: sh\n\n    $ pip install django-formapi\n\nAdd ``formapi`` to your ``INSTALLED_APPS`` setting.\n\n.. code:: python\n\n    INSTALLED_APPS = (\n        ...,\n        \"formapi\",\n    )\n\nAdd ``formapi.urls`` to your urls.py.\n\n.. code:: python\n\n  urlpatterns = [\n      ...,\n      url(r\"^api/\", include(\"formapi.urls\")),\n  ]\n\nUsage\n-----\n\nGo ahead and create a ``calls.py``.\n\n.. code:: python\n\n  class DivisionCall(calls.APICall):\n      \"\"\"\n      Returns the quotient of two integers\n      \"\"\"\n\n      dividend = forms.FloatField()\n      divisor = forms.FloatField()\n\n      def action(self, test):\n          dividend = self.cleaned_data.get(\"dividend\")\n          divisor = self.cleaned_data.get(\"divisor\")\n          return dividend / divisor\n\n\n  API.register(DivisionCall, \"math\", \"divide\", version=\"v1.0.0\")\n\n\nJust create a class like your regular Django Forms but inheriting from ``APICall``. Define the fields that your API-call\nshould receive. The ``action`` method is called when your fields have been validated and what is returned will be JSON-encoded\nas a response to the API-caller. The ``API.register`` call takes your ``APICall``-class as first argument, the second argument is\nthe ``namespace`` the API-call should reside in, the third argument is the ``name`` of your call and the fourth the ``version``.\nThis will result in an url in the form of ``api/[version]/[namespace]/[call_name]/`` so we would get ``/api/v1.0.0/math/divide/``.\n\nA valid call with the parameters ``{'dividend': 5, 'divisor': 2}`` would result in this response:\n\n.. code:: javascript\n\n  {\"errors\": {}, \"data\": 5, \"success\": true}\n\nAn invalid call with the parameters ``{'dividend': \"five\", 'divisor': 2}`` would result in this response:\n\n.. code:: javascript\n\n  {\"errors\": {\"dividend\": [\"Enter a number.\"]}, \"data\": false, \"success\": false}\n\n\nAuthentication\n--------------\nBy default ``APICalls`` have HMAC-authentication turned on. Disable it by setting ``signed_requests = False`` on your ``APICall``.\n\nIf not disabled users of the API will have to sign their calls. To do this they need a ``secret`` generate, create a ``APIKey`` through the django\nadmin interface. On save a personal ``secret`` and ``key`` will be generated for the API-user.\n\nTo build a call signature for the ``DivisonCall`` create a querystring of the calls parameters sorted by the keys ``dividend=5\u0026divisor=2``. Create a HMAC using SHA1 hash function.\nExample in python:\n\n.. code:: python\n\n  import hmac\n  from hashlib import sha1\n\n  hmac_sign = hmac.new(secret, urllib2.quote(\"dividend=5\u0026divisor=2\"), sha1).hexdigest()\n\nA signed request against ``DivisionCall`` would have the parameters ``{'dividend': 5, 'divisor': 2, 'key': generated_key, 'sign': hmac_sign}``\n\nDocumentation\n-------------\nVisit ``/api/discover`` for a brief documentation of the registered API-calls.\n","funding_links":[],"categories":["资源列表","Python","RESTful API"],"sub_categories":["RESTful API"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5monkeys%2Fdjango-formapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F5monkeys%2Fdjango-formapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5monkeys%2Fdjango-formapi/lists"}