{"id":24617815,"url":"https://github.com/jacoblincool/sveltekit-api","last_synced_at":"2025-07-20T12:06:04.221Z","repository":{"id":176149141,"uuid":"654969338","full_name":"JacobLinCool/sveltekit-api","owner":"JacobLinCool","description":"Handles all kinds of SvelteKit data flows in one place, and automatically generate OpenAPI documentation.","archived":false,"fork":false,"pushed_at":"2025-07-20T04:13:38.000Z","size":325,"stargazers_count":47,"open_issues_count":15,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-20T06:35:38.564Z","etag":null,"topics":["api","openapi","sveltekit"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sveltekit-api","language":"TypeScript","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/JacobLinCool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2023-06-17T13:36:42.000Z","updated_at":"2025-07-06T02:22:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"b94f3d20-5ae2-4e72-8258-ff977876e54e","html_url":"https://github.com/JacobLinCool/sveltekit-api","commit_stats":null,"previous_names":["jacoblincool/sveltekit-api"],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/JacobLinCool/sveltekit-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fsveltekit-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fsveltekit-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fsveltekit-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fsveltekit-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JacobLinCool","download_url":"https://codeload.github.com/JacobLinCool/sveltekit-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JacobLinCool%2Fsveltekit-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266080240,"owners_count":23873503,"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":["api","openapi","sveltekit"],"created_at":"2025-01-24T23:41:05.590Z","updated_at":"2025-07-20T12:06:04.205Z","avatar_url":"https://github.com/JacobLinCool.png","language":"TypeScript","readme":"# SvelteKit-API\n\nHandles all kinds of SvelteKit data flows in one place, and automatically generate OpenAPI documentation.\n\n## Features\n\n- [x] `API`: Manage API endpoints and automatically generate OpenAPI documentation\n\n## Installation\n\n```bash\npnpm i -D sveltekit-api\n```\n\n## Projects using SvelteKit-API\n\nThese projects are using SvelteKit-API and can be used as examples:\n\n- [WASM OJ Wonderland](https://github.com/wasm-oj/wonderland): A SvelteKit-based online judge system core.\n- [PEA](https://github.com/JacobLinCool/pea): A serverless email authentication and verification service.\n- Add your project here by submitting a pull request!\n\n## Usage\n\n### `API`\n\nAdd `$api` to your `svelte.config.js`:\n\n```js\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n  kit: {\n    alias: {\n      \"$api\": \"./src/api\",\n    },\n  },\n};\n```\n\nCreate the API endpoints in the structure like [`src/api`](./src/api).\n\n```ts\n// for example:\nsrc\n├── api\n│   ├── index.ts\n│   └── post\n│       ├── GET.ts\n│       ├── POST.ts\n│       ├── [...id]\n│       │   └── GET.ts\n│       └── search\n│           └── GET.ts\n├── lib\n│   └── ...\n└── routes\n    └── ...\n```\n\n```ts\n// file: src/api/index.ts\nimport { API } from \"sveltekit-api\";\n\nexport default new API(import.meta.glob(\"./**/*.ts\"), {\n  openapi: \"3.0.0\",\n  info: {\n    title: \"Simple Post API\",\n    version: \"1.0.0\",\n    description: \"An example API\",\n  },\n});\n```\n\n```ts\n// file: src/api/post/[...id]/PUT.ts\nimport { Endpoint, z, error } from \"sveltekit-api\";\nimport { posts, type Post } from \"../../db.js\";\n\nexport const Query = z.object({\n  password: z.string().optional(),\n});\n\nexport const Param = z.object({\n  id: z.string(),\n});\n\nexport const Input = z.object({\n  title: z.string(),\n  content: z.string(),\n  author: z.string(),\n});\n\nexport const Output = z.object({\n  id: z.string(),\n  title: z.string(),\n  content: z.string(),\n  author: z.string(),\n  date: z.string(),\n}) satisfies z.ZodSchema\u003cPost\u003e;\n\nexport const Error = {\n  404: error(404, \"Post not found\"),\n  403: error(403, \"Forbidden\"),\n};\n\nexport default new Endpoint({ Param, Query, Input, Output, Error }).handle(async (param) =\u003e {\n  const post = posts.get(param.id);\n\n  if (!post) {\n    throw Error[404];\n  }\n\n  if (post.password \u0026\u0026 post.password !== param.password) {\n    throw Error[403];\n  }\n\n  post.title = param.title;\n  post.content = param.content;\n  post.author = param.author;\n\n  return post;\n});\n```\n\nCall the API handler and OpenAPI generator in your routes like [`src/routes/api`](./src/routes/api).\n\n```ts\n// file: src/routes/+server.ts\nimport api from \"$api\";\nimport { json } from \"@sveltejs/kit\";\n\nexport const prerender = true;\n\nexport const GET = async (evt) =\u003e json(await api.openapi(evt));\n```\n\n```ts\n// file: src/routes/api/post/+server.ts\nimport api from \"$api\";\n\nexport const GET = async (evt) =\u003e api.handle(evt);\nexport const POST = async (evt) =\u003e api.handle(evt);\nexport const OPTIONS = async (evt) =\u003e api.handle(evt);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fsveltekit-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacoblincool%2Fsveltekit-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoblincool%2Fsveltekit-api/lists"}