{"id":17205052,"url":"https://github.com/ahmethakanbesel/http-socket","last_synced_at":"2025-03-25T10:16:28.328Z","repository":{"id":153379372,"uuid":"597663460","full_name":"ahmethakanbesel/http-socket","owner":"ahmethakanbesel","description":"A socket level HTTP server and client implementation in Python. Only GET and POST methods are implemented. Educational purposes only, not suitable for production.","archived":false,"fork":false,"pushed_at":"2023-02-05T08:47:42.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T09:24:59.941Z","etag":null,"topics":["http","http-client","http-server","multithreading","socket","socket-programming"],"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/ahmethakanbesel.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-02-05T08:42:50.000Z","updated_at":"2023-03-11T16:49:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb545356-5d91-4284-ba54-a464437b6d7e","html_url":"https://github.com/ahmethakanbesel/http-socket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmethakanbesel%2Fhttp-socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmethakanbesel%2Fhttp-socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmethakanbesel%2Fhttp-socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmethakanbesel%2Fhttp-socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmethakanbesel","download_url":"https://codeload.github.com/ahmethakanbesel/http-socket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245440577,"owners_count":20615633,"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-client","http-server","multithreading","socket","socket-programming"],"created_at":"2024-10-15T02:24:11.413Z","updated_at":"2025-03-25T10:16:28.294Z","avatar_url":"https://github.com/ahmethakanbesel.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multi-threaded HTTP Socket Server and HTTP Client\nA socket level HTTP server and client implementation in Python.\nOnly GET and POST methods are implemented. Educational purposes only, not suitable for production.\n## HTTP Server Usage\n\n### Create a handler to handle incoming requests\n```python\nfrom http_server import BaseHandler\nfrom templates import get_template\n\n\nclass IndexHandler(BaseHandler):\n  def get(self):\n    self.response = get_template('base').format('Homepage', 'Homepage',\n                                                \"\u003cp\u003eMethod: GET\u003c/p\u003e\u003ch2\u003eQuery Params\u003c/h2\u003e\u003cpre\u003e{}\u003c/pre\u003e\".format(\n                                                  self.request['params']))\n    pass\n\n  def post(self):\n    self.response = get_template('base').format('Homepage', 'Homepage',\n                                                \"\u003cp\u003eMethod: POST\u003c/p\u003e\u003ch2\u003ePost Fields\u003c/h2\u003e\u003cpre\u003e{}\u003c/pre\u003e\".format(\n                                                  self.request['form']))\n    pass\n```\n\n### Create a multi-threaded HTTP server and define routes\n\n```python\nfrom http_server import HTTPServer\nfrom handlers import IndexHandler\n\nexample_server = HTTPServer('localhost', 8000, 5, {\n  \"/\": IndexHandler,\n})\nexample_server.start()\n```\n\n## HTTP Client Usage\n\n```python\nimport socket\nfrom http_client.client import get_status_code\nfrom http_client import client, parse_response\n\n# GET request\nsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\nresponse = client.request('GET', 'localhost', 8000, '/index',\n               sock)\nresponse = parse_response(response)\n# Retrieve only status code\nstatus_code = get_status_code('GET', 'localhost', 8000, '/index')\n```\n## Benchmarking\nA simple configuration for Locust can be found in `locustfile.py`.\nIf you have not installed Locust yet you can install it by\n```bash\npip install locust\n```\nThen run `locust` command in your terminal to start Locust.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmethakanbesel%2Fhttp-socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmethakanbesel%2Fhttp-socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmethakanbesel%2Fhttp-socket/lists"}