{"id":16678938,"url":"https://github.com/joncloud/simple-api","last_synced_at":"2026-04-27T14:31:39.713Z","repository":{"id":78825340,"uuid":"591778140","full_name":"joncloud/simple-api","owner":"joncloud","description":"This project is an experimental simple API, which exposes a server and client package.","archived":false,"fork":false,"pushed_at":"2023-01-21T20:47:33.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-29T14:32:11.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/joncloud.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-01-21T20:47:09.000Z","updated_at":"2023-01-21T20:47:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"555eb87c-0c81-45b6-9b5b-8ed223bc64ee","html_url":"https://github.com/joncloud/simple-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joncloud/simple-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fsimple-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fsimple-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fsimple-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fsimple-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joncloud","download_url":"https://codeload.github.com/joncloud/simple-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joncloud%2Fsimple-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32341447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"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":[],"created_at":"2024-10-12T13:32:21.931Z","updated_at":"2026-04-27T14:31:39.694Z","avatar_url":"https://github.com/joncloud.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Typescript API Server and Client\n\nThis project is an experimental simple API, which exposes a server and client package.\n\n## Requirements\n\n* Node.js 18\n\n## Server\n\nThe server package is built on top of `express`, and leverages `zod` for declaring types for validation.\n\n### Launching the server\n\n```bash\ncd packages/server\nnpm run start\n```\n\n## Client\n\nThe client package is built by generating Typescript types from the server using `zod-to-ts`, and leverages the type system to expose a factory that creates functions for making strongly typed calls into the server. The resulting function will optionally take parameters based on how the client API is defined:\n\n  1. The route to the API\n  2. The method to invoke on the API (GET, POST, etc.)\n  3. For methods that define a body - The content type of the request\n  4. For methods that define a body, headers or query arguments - An object that includes each of those as fields\n  5. An optional remaining argument for any additional `RequestInit` arguments excluding those that have already been specified.\n\n### Creating an API\n\nCreating an API requires two things:\n\n* A generic argument, which defines the API schema\n* A parameter, which defines the root URL of the API\n\n```typescript\nimport { api } from './api';\n\nexport type HelloApi =\n  {\n    'hello': {\n      get: {\n        query: { name: string },\n        ok: { message: string },\n        err: { message: string },\n      },\n    },\n  }\n\nconst rootUrl = 'http://localhost:3000';\nconst hello = api\u003cHelloApi\u003e(rootUrl, { });\n```\n\n### Invoking the API\n\nWhen invoking the API the return result includes a tuple with the following entries:\n\n1. The partial type expected when the server responds with an ok status code\n2. The partial type expected when the server responds with a non-ok status code\n3. The raw response (with the body already read)\n\n```typescript\nconst [ok, err, res] = await hello('hello', 'get', {\n  query: { name: 'get query' },\n});\nif (ok) {\n  console.log('great job!', ok.message);\n} else if (err) {\n  console.error('uh oh!', err.message);\n}\nconsole.debug('http status', res.status);\n```\n\nPerform type checking against `ok` and `err` to determine what the server responded with. The API will never return both a non-null `ok` and `err`.\n\n### Raw response access\n\nAPIs include a `raw` function, which provides typed access to the parameters, but does not attempt to perform any additional processing on top of the `Response`.\n\n```typescript\nconst res = await hello.raw('hello', 'get', {\n  query: { name: 'get query' },\n});\nconsole.log('http body', await res.text());\nconsole.debug('http status', res.status);\n```\n\n### Running tests\n\n```bash\ncd packages/client\nnpm run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoncloud%2Fsimple-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoncloud%2Fsimple-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoncloud%2Fsimple-api/lists"}