{"id":24550308,"url":"https://github.com/cansik/duit-rest","last_synced_at":"2026-02-10T17:04:49.073Z","repository":{"id":272728900,"uuid":"720002753","full_name":"cansik/duit-rest","owner":"cansik","description":"A web based REST API for the duit library.","archived":false,"fork":false,"pushed_at":"2025-01-16T09:21:52.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-17T04:44:08.959Z","etag":null,"topics":["duit","rest-api"],"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/cansik.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-17T11:16:10.000Z","updated_at":"2025-01-16T09:29:44.000Z","dependencies_parsed_at":"2025-01-16T09:59:20.265Z","dependency_job_id":"822d29af-fe74-45e5-8066-69f4c1114905","html_url":"https://github.com/cansik/duit-rest","commit_stats":null,"previous_names":["cansik/duit-rest"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cansik/duit-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansik%2Fduit-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansik%2Fduit-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansik%2Fduit-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansik%2Fduit-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cansik","download_url":"https://codeload.github.com/cansik/duit-rest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cansik%2Fduit-rest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29308947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T16:09:25.305Z","status":"ssl_error","status_checked_at":"2026-02-10T16:08:52.170Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["duit","rest-api"],"created_at":"2025-01-23T00:35:10.523Z","updated_at":"2026-02-10T17:04:49.047Z","avatar_url":"https://github.com/cansik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REST for Duit\n\n[![PyPI](https://img.shields.io/pypi/v/duit-rest)](https://pypi.org/project/duit-rest/)\n[![Github](https://img.shields.io/badge/duit-rest?logo=github\u0026label=github\u0026color=green)](https://github.com/cansik/duit-rest)\n\nA web-based REST API for duit datafields.\n\nThis is an addon module for the data ui toolkit ([duit](https://github.com/cansik/duit)) which adds REST API support\nfor [DataFields](https://cansik.github.io/duit/duit.html#data-field).\n\n## Installation\n\nThe package can be installed directly from [PyPI](https://pypi.org/project/duit-rest/).\n\n```\n\npip install duit-rest\n\n```\n\n## Documentation\n\nDuit-rest uses [FastAPI](https://fastapi.tiangolo.com/) as REST backend to handle HTTP requests. The main class is the\n`RESTService` which handles the HTTP server and maps the annotated `DataFields` to the corresponding endpoints.\n\n### RESTEndpoint\n\nIt is possible to annotate existing `DataFields` with the `RESTEndpoint` annotation. This annotation later tells the\n`RESTService` if the field has to be exposed over REST. It is recommended to gather all DataFields in a single object:\n\n```python\nfrom duit_rest.RESTEndpoint import RESTEndpoint\n\n\nclass Config:\n    def __init__(self):\n        self.name = DataField(\"Cat\") | RESTEndpoint()\n```\n\nBy default, the name of the variable (e.g. `name`) is used as REST endpoint identifier. It is possible to change the\nname through the `RESTEndpoint` annotation.\n\n```python\nself.name = DataField(\"Cat\") | RESTEndpoint(name=\"the-cats-name\")\n```\n\n### RESTService\n\nThe RESTService handles the HTTP server and mapping with the `DataFields`. Here is a simple example on how to create a\n`RESTService`, add the previously defined config and start the service.\n\n```python\n# create an actual instance of the config\nconfig = Config()\n\n# create a rest service\nrest_service = RESTService()\n\n# add the config object (create mapping) under the route \"/config\"\nrest_service.add_route(\"/config\", config)\n\n# run the service\nrest_service.run()\n```\n\n#### Settings\n\nThe `RESTService` has several default arguments that can be changed before the service is started:\n\n```python\n# RESTService parameters and their default values\nhost: str = \"0.0.0.0\",  # on which interface the service is running\nport: int = 9420,  # on which port the service is running\ntitle: str = \"REST API\"  # title of the API\n```\n\n#### Routes\n\nIt is possible to add various objects to the RESTService, each with a unique route (address).\n\n```python\nrest_service.add_route(\"/config\", config)\n```\n\nEach `DataField` is accessible under this route, so for example the `name` field would be available at `/config/name`.\n\n#### API Usage\n\nGetting values:\n\n```bash\n# Get entire configuration\nGET http://localhost:9420/config\n\n# Get specific field\nGET http://localhost:9420/config/name\n```\n\nSetting values:\n\n```bash\n# Update entire configuration\nPOST http://localhost:9420/config\nContent-Type: application/json\n\n{\n    \"name\": \"NewName\",\n    \"age\": 25\n}\n\n# Update specific field\nGET http://localhost:9420/config/name?value=\"NewName\"\n```\n\n#### Start\n\nTo start the service, call the `run()` method. This is a blocking method that doesn't return until the service is\nshutdown:\n\n```python\n# run blocking\nrest_service.run()\n```\n\nTo start the service in its own thread, set the `blocking` argument to `False:\n\n```python\n# run non-blocking\nthread = rest_service.run(blocking=False)\n```\n\n## About\n\nCopyright (c) 2025 Florian Bruggisser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcansik%2Fduit-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcansik%2Fduit-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcansik%2Fduit-rest/lists"}