{"id":17491786,"url":"https://github.com/peinz/enapi","last_synced_at":"2026-05-15T08:33:39.769Z","repository":{"id":58026171,"uuid":"525879531","full_name":"peinz/enapi","owner":"peinz","description":"Entity based API-Platform","archived":false,"fork":false,"pushed_at":"2022-09-10T15:31:27.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-11T16:59:45.936Z","etag":null,"topics":["api","deno","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peinz.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-17T16:47:00.000Z","updated_at":"2022-08-27T21:48:15.000Z","dependencies_parsed_at":"2022-09-08T01:21:23.745Z","dependency_job_id":null,"html_url":"https://github.com/peinz/enapi","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/peinz/enapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peinz%2Fenapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peinz%2Fenapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peinz%2Fenapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peinz%2Fenapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peinz","download_url":"https://codeload.github.com/peinz/enapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peinz%2Fenapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273542657,"owners_count":25124204,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["api","deno","typescript"],"created_at":"2024-10-19T08:04:59.329Z","updated_at":"2025-10-18T09:06:31.691Z","avatar_url":"https://github.com/peinz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Entity API\n\nEntity based API-Platform\n\nThe aim of this project is to create a lightweight and easy to use library, that\nprovides you with typesupport on the backend as well as the frontend.\n\nYou start by defining your api-schema in code. That will you provide you with\ntypesupport for you server implementation, and for you api client. Without code\ngeneration.\\\nYou can also use your schema to generate an\n[openapi documentation](https://swagger.io/specification/)\n\nSupported actions are: get, post, patch, delete, getCollection\n\n## Usage\n\n### 1. Define your api-schema\n\n```typescript\nconst foo_endpoint_def = createEndpointDefinition({\n  getResult: {\n    id: \"number\",\n    name: \"string\",\n  },\n  postBody: {\n    name: \"string\",\n  },\n});\n```\n\n### 2. Implement your RequestHandler\n\n```typescript\nlet c = 0;\nconst foos = {} as Record\u003cnumber, { id: number; name: string }\u003e;\n\nconst foo_endpoint_impl = createEndpointImplementation\u003c\n  typeof foo_endpoint_def\n\u003e({\n  get: (id) =\u003e foos[id],\n  post: (body) =\u003e foos[++c] = { ...body, id: c },\n});\n```\n\n### 3. Choose your favorite webserver (enapi is web-server agnostic)\n\n```typescript\nimport {\n  createOpenApiJsonDoc,\n  RequestHandler,\n} from \"https://deno.land/x/enapi/mod.ts\";\nimport { json, opine } from \"https://deno.land/x/opine@2.0.0/mod.ts\";\nimport { opineCors } from \"https://deno.land/x/cors@v1.2.2/mod.ts\";\nimport { endpoints } from \"./api.ts\";\n\nconst api_base_url = \"http://localhost:3000\";\n\nconst requestHandler = RequestHandler(endpoints);\n\nconst server = opine();\nserver.use(opineCors());\nserver.use(json());\n\n// handle entity requests\nserver.use(async (req, res, next) =\u003e {\n  const result = await requestHandler.handle({\n    method: req.method as any,\n    url: req.url.split(\"?\")[0],\n    body: req.parsedBody,\n    queryParams: req.query,\n  });\n\n  if (!result) next();\n  else res.setStatus(result.statusCode).json(result.body);\n});\n\n// provide openapi documentation\nserver.get(\"/_docs.openapi\", (_req, res) =\u003e {\n  const doc = createOpenApiJsonDoc(api_base_url, endpoints);\n  res.json(doc);\n});\n\nserver.listen(\n  3000,\n  () =\u003e console.log(`server has started on ${api_base_url} 🚀`),\n);\n```\n\n### 4. Call your api on the frontend\n\n```typescript\nimport { endpoints } from \"./api.ts\";\nimport { Client } from \"https://deno.land/x/enapi/mod.ts\";\n\nconst client = Client(\"http://localhost:3000\", endpoints);\n\nconst data_post_result = await client.post.foo({ name: \"dfg\" });\nconst data_get_result = await client.get.foo(data_post_result.id);\n\nconsole.log(data_get_result);\n```\n\n## Future Plans\n\n- add more entity property types\n- support entity-relations\n- include errors in return types\n- support transactions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeinz%2Fenapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeinz%2Fenapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeinz%2Fenapi/lists"}