{"id":13599149,"url":"https://github.com/ymzuiku/svelte-zero-api","last_synced_at":"2025-08-01T15:37:13.567Z","repository":{"id":43488708,"uuid":"370385550","full_name":"ymzuiku/svelte-zero-api","owner":"ymzuiku","description":"Use Svelte Kit APIs like client functions, support Typescript.","archived":false,"fork":false,"pushed_at":"2023-07-28T08:37:53.000Z","size":118,"stargazers_count":22,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T05:35:01.160Z","etag":null,"topics":["svelte","svelte-kit","zero-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ymzuiku.png","metadata":{"files":{"readme":"README-not-watch.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,"zenodo":null}},"created_at":"2021-05-24T14:44:05.000Z","updated_at":"2024-05-15T09:54:14.000Z","dependencies_parsed_at":"2025-05-15T18:38:30.010Z","dependency_job_id":"a57a7282-3a2f-4f26-bd96-94cb5586f86f","html_url":"https://github.com/ymzuiku/svelte-zero-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ymzuiku/svelte-zero-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fsvelte-zero-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fsvelte-zero-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fsvelte-zero-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fsvelte-zero-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ymzuiku","download_url":"https://codeload.github.com/ymzuiku/svelte-zero-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymzuiku%2Fsvelte-zero-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268214064,"owners_count":24214352,"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-08-01T02:00:08.611Z","response_time":67,"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":["svelte","svelte-kit","zero-api"],"created_at":"2024-08-01T17:01:00.267Z","updated_at":"2025-08-01T15:37:13.492Z","avatar_url":"https://github.com/ymzuiku.png","language":"JavaScript","readme":"## How about dont't use style-zero-api/watch?\n\n\u003e only use coding and not edit `svelte.config.js`\n\n1 - Create A POST api in `src/routes/api/hello.ts`:\n\n```ts\ninterface Props {\n  body: {\n    name: string;\n  };\n}\n\n// Must export a Promise function\nexport const get = async ({ query }: Props) =\u003e {\n  return { world: { out: \"I'm a \" + query.name } };\n};\n\n// Must export a Promise function\nexport const post = async ({ body }: Props) =\u003e {\n  return { world: { out: \"You are a \" + body.name } };\n};\n```\n\n2 - Create Some index.d.ts for APIs in `src/routes/api/index.d.ts`:\n\n```ts\nimport * as hello from \"./hello\";\n\n// Export default object tree must equal svelte kit api fetch route\nexport default { hello };\n```\n\n3 - Create api functions by `svelte-zero-api` in `src/api.ts`:\n\n```ts\nimport { createZeroApi } from \"./zeroApi\";\nimport type API from \"../routes/api\";\n\nexport const api = createZeroApi\u003ctypeof API\u003e({ baseUrl: \"/api\" });\n```\n\n4 - Use all api function in front-end pages, example:\n\nat `src/routes/index.svelte`\n\n```ts\n\u003cscript lang=\"ts\"\u003e\n  import { api } from \"../tools/api\";\n\n  import Button from \"../lib/Button.svelte\";\n\n  // We can use api before onMount, because api function only run in browser.\n  // like front end function, and have Typescrit point out.\n  let helloGet = api.hello.get({ query: { name: \"Cat\" } });\n  let helloPost = api.hello.post({ body: { name: \"Dog\" } });\n\u003c/script\u003e\n\n{#await helloFetch}\n\t\u003cdiv\u003eloading...\u003c/div\u003e\n{:then res}\n\t\u003cdiv\u003e{res.body.world}\u003c/div\u003e\n{/await}\n\n```\n\n5 - If you have some api files like tree:\n\n```\n- src/routes/api\n    - hello.ts\n    - company\n        - user\n        - storage\n```\n\n`src/routes/api/index.d.ts` need like this:\n\n```ts\nimport * as hello from \"./hello\";\nimport * as user from \"./company/user\";\nimport * as storage from \"./company/storage\";\n\n// Export default object tree must equal svelte kit api fetch route\nexport default {\n  hello,\n  company: {\n    user,\n    storage,\n  },\n};\n```\n","funding_links":[],"categories":["Meta-Meta"],"sub_categories":["The _How To's?_"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymzuiku%2Fsvelte-zero-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fymzuiku%2Fsvelte-zero-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymzuiku%2Fsvelte-zero-api/lists"}