{"id":20130307,"url":"https://github.com/pavelrevak/uhttp","last_synced_at":"2025-03-02T21:42:24.841Z","repository":{"id":214341268,"uuid":"736285215","full_name":"pavelrevak/uhttp","owner":"pavelrevak","description":"uHTTP simple HTTP server for micropython","archived":false,"fork":false,"pushed_at":"2024-01-27T11:33:02.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T08:46:08.010Z","etag":null,"topics":["http","http-server","micropython","python"],"latest_commit_sha":null,"homepage":"","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/pavelrevak.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-27T13:40:55.000Z","updated_at":"2023-12-28T16:28:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"499360c7-f0c0-4ddd-be5b-1e78b3dad374","html_url":"https://github.com/pavelrevak/uhttp","commit_stats":null,"previous_names":["pavelrevak/uhttp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavelrevak%2Fuhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavelrevak%2Fuhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavelrevak%2Fuhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pavelrevak%2Fuhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pavelrevak","download_url":"https://codeload.github.com/pavelrevak/uhttp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241577070,"owners_count":19984940,"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":["http","http-server","micropython","python"],"created_at":"2024-11-13T20:38:07.702Z","updated_at":"2025-03-02T21:42:24.667Z","avatar_url":"https://github.com/pavelrevak.png","language":"Python","readme":"# uHTTP: micro HTTP server\n\n\n## Features:\n\n- support MicroPython and also cPython\n- minimalist and low level implementation using posix sockets\n- is fully synchronous (not uses ASYNC or multiple threads) but can work with multiple connections\n- support delayed response, user can hold client instance and reply later\n- support for raw data (HTML, binary, ...) and also for JSON (send and receive)\n- need at least 32KB RAM to work (depends on configured limits)\n- do many check for bad requests and or headers, and many errors will not break this\n\n\n## usage\n\n```python\nimport uhttp\n\nserver = uhttp.HttpServer(port=9980)\n\nwhile True:\n    client = server.wait()\n    if client:\n        if client.path == '/':\n            # result is html\n            client.respond(\"\u003ch1\u003ehello\u003c/h1\u003e\u003cp\u003euHTTP\u003c/p\u003e\")\n        elif client.path == '/rpc':\n            # result is json\n            client.respond({'message': 'hello', 'success': True, 'headers': client.headers, 'query': client.query})\n        else:\n            client.respond(\"Not found\", status=404)\n\n```\n\n\n## API\n\n### General methods:\n\n**`import uhttp`**\n\n**`uhttp.decode_percent_encoding(data)`**\n\n- Decode percent encoded data (bytes)\n\n**`uhttp.parse_header_parameters(value)`**\n\n- Parse parameters/directives from header value, returns dict\n\n**`uhttp.parse_query(raw_query, query=None)`**\n\n- Parse raw_query from URL, append it to existing query, returns dict\n\n**`uhttp.parse_url(url)`**\n\n- Parse URL to path and query\n\n**`uhttp.parse_header_line(line)`**\n\n- Parse header line to key and value\n\n**`uhttp.encode_response_data(headers, data)`**\n\n- Encode response data by its type\n\n\n### Class `HttpServer`:\n\n**`HttpServer(address='0.0.0.0', port=80)`**\n\n#### Properties:\n\n**`socket(self)`**\n\n- Server socket\n\n**`read_sockets(self)`**\n\n- All sockets waiting for communication, used for select\n\n#### Methods:\n\n**`process_events(self, read_events)`**\n\n- Process sockets with read_events, returns None or instance of HttpClient with established connection\n\n**`wait(self, timeout=1)`**\n\n- Wait for new clients with specified timeout, returns None or instance of HttpClient with established connection\n\n\n### Class `HttpClient`:\n\n**`HttpClient(sock, addr)`**\n\n#### Properties:\n\n**`addr(self)`**\n\n- Client address\n\n**`method(self)`**\n\n- HTTP method\n\n**`url(self)`**\n\n- URL address\n\n**`host(self)`**\n\n- URL address\n\n**`full_url(self)`**\n\n- URL address\n\n**`protocol(self)`**\n\n- Protocol\n\n**`headers(self)`**\n\n- headers dict\n\n**`data(self)`**\n\n- Content data\n\n**`path(self)`**\n\n- Path\n\n**`query(self)`**\n\n- Query dict\n\n**`cookies(self)`**\n\n- Query dict\n\n**`socket(self)`**\n\n- This socket\n\n**`is_loaded_all(self)`**\n\n- State if request is fully loaded\n\n**`content_length(self)`**\n\n- Content length\n\n#### Methods:\n\n**`headers_get(self, key, default=None)`**\n\n- Return value from headers by key, or default if key not found\n\n**`process_request(self)`**\n\n- Process HTTP request when read event on client socket\n\n**`respond(self, data=None, status=200, headers=None, cookies=None)`**\n\n- Create general response with data, status and headers as dict\n\n**`respond_redirect(self, url, status=302, cookies=None)`**\n\n- Create redirect response to URL\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavelrevak%2Fuhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpavelrevak%2Fuhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpavelrevak%2Fuhttp/lists"}