{"id":18086898,"url":"https://github.com/denismakogon/hotfn-py","last_synced_at":"2025-04-13T00:52:14.273Z","repository":{"id":62569460,"uuid":"86222726","full_name":"denismakogon/hotfn-py","owner":"denismakogon","description":"Routine to work with raw HTTP over STDIN/STDOUT","archived":false,"fork":false,"pushed_at":"2022-07-05T21:07:44.000Z","size":66,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T18:52:28.699Z","etag":null,"topics":["fnproject","http","http-over-stdin-stdout","server","serverless"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denismakogon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-26T09:54:48.000Z","updated_at":"2022-10-31T07:59:58.000Z","dependencies_parsed_at":"2022-11-03T17:15:30.444Z","dependency_job_id":null,"html_url":"https://github.com/denismakogon/hotfn-py","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismakogon%2Fhotfn-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismakogon%2Fhotfn-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismakogon%2Fhotfn-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denismakogon%2Fhotfn-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denismakogon","download_url":"https://codeload.github.com/denismakogon/hotfn-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650435,"owners_count":21139672,"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":["fnproject","http","http-over-stdin-stdout","server","serverless"],"created_at":"2024-10-31T16:59:20.084Z","updated_at":"2025-04-13T00:52:14.233Z","avatar_url":"https://github.com/denismakogon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/denismakogon/hotfn-py.svg?branch=master)](https://travis-ci.org/denismakogon/hotfn-py)\n\nHTTP over STDIN/STDOUT lib parser\n=================================\n\nPurpose of this library to provide simple interface to parse HTTP 1.1 requests represented as string\n\nFollowing examples are showing how to use API of this library to work with streaming HTTP requests from Fn service.\n\nHandling Hot HTTP Functions\n---------------------------\n\nA main loop is supplied that can repeatedly call a user function with a series of HTTP requests.\nIn order to utilise this, you can write your `app.py` as follows:\n\n```python\nfrom hotfn.http import worker\nfrom hotfn.http import response\n\n\ndef app(context, **kwargs):\n    body = kwargs.get('data')\n    return response.RawResponse(context.version, 200, \"OK\", body.readall())\n\n\nif __name__ == \"__main__\":\n    worker.run(app)\n\n```\n\nAutomatic HTTP input coercions\n------------------------------\n\nDecorators are provided that will attempt to coerce input values to Python types.\nSome attempt is made to coerce return values from these functions also:\n\n```python\nfrom hotfn.http import worker\n\n\n@worker.coerce_input_to_content_type\ndef app(context, **kwargs):\n    \"\"\"\n    body is a request body, it's type depends on content type\n    \"\"\"\n    return kwargs.get('data')\n\n\nif __name__ == \"__main__\":\n    worker.run(app)\n\n```\n\nWorking with async automatic HTTP input coercions\n-------------------------------------------------\n\nLatest version (from 0.0.6) supports async coroutines as a request body processors:\n```python\n\nimport asyncio\n\nfrom hotfn.http import worker\nfrom hotfn.http import response\n\n\n@worker.coerce_input_to_content_type\nasync def app(context, **kwargs):\n    headers = {\n        \"Content-Type\": \"plain/text\",\n    }\n    return response.RawResponse(\n        context.version, 200, \"OK\",\n        http_headers=headers,\n        response_data=\"OK\")\n\n\nif __name__ == \"__main__\":\n    loop = asyncio.get_event_loop()\n    worker.run(app, loop=loop)\n\n```\n\nHandling Hot JSON Functions\n---------------------------\n\nA main loop is supplied that can repeatedly call a user function with a series of JSON requests.\nIn order to utilise this, you can write your `app.py` as follows:\n\n```python\nfrom hotfn.json import worker\n\n\ndef handler(context, data=None, loop=None):\n    return data\n\n\nif __name__ == \"__main__\":\n    worker.run(handler)\n\n```\n\nWorking with async Hot JSON Functions\n-------------------------------------\n\nLatest version (from 0.0.6) supports async coroutines as a request body processors:\n```python\n\nimport asyncio\n\nfrom hotfn.json import worker\n\n\nasync def handler(context, data=None, loop=None):\n    return data\n\n\nif __name__ == \"__main__\":\n    loop = asyncio.get_event_loop()\n    worker.run(handler, loop=loop)\n\n```\n\n\nAs you can see `app` function is no longer callable, because its type: coroutine, so we need to bypass event loop inside ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenismakogon%2Fhotfn-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenismakogon%2Fhotfn-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenismakogon%2Fhotfn-py/lists"}