{"id":19858525,"url":"https://github.com/matjam/svelte-jsonplaceholder-ts-example","last_synced_at":"2025-09-18T22:44:43.840Z","repository":{"id":139867334,"uuid":"579202278","full_name":"matjam/svelte-jsonplaceholder-ts-example","owner":"matjam","description":"Example of calling rest APIs from a sveltekit app","archived":false,"fork":false,"pushed_at":"2022-12-17T01:33:43.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-22T17:07:51.606Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matjam.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-16T23:20:48.000Z","updated_at":"2022-12-21T12:10:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"723a2a42-92a2-457e-9972-8bf5e17dbbbc","html_url":"https://github.com/matjam/svelte-jsonplaceholder-ts-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/matjam/svelte-jsonplaceholder-ts-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matjam%2Fsvelte-jsonplaceholder-ts-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matjam%2Fsvelte-jsonplaceholder-ts-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matjam%2Fsvelte-jsonplaceholder-ts-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matjam%2Fsvelte-jsonplaceholder-ts-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matjam","download_url":"https://codeload.github.com/matjam/svelte-jsonplaceholder-ts-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matjam%2Fsvelte-jsonplaceholder-ts-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275845324,"owners_count":25538996,"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-18T02:00:09.552Z","response_time":77,"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-11-12T14:23:46.510Z","updated_at":"2025-09-18T22:44:43.822Z","avatar_url":"https://github.com/matjam.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svelte-jsonplaceholder-ts-example\n\nThis project is a work in progress example of a svelte project using an\nexternal API written in TypeScript.\n\nI was finding it difficult to figure this out but with some reading of\ndocs, (pro tip, there's a \"TS\" toggle at the bottom left of the SvelteKit\ndocs page) along with asking colleagues questions, I have got things\nworking.\n\nI don't demonstrate ALL the kinds of things sveltekit does, but I do\ndemonstrate how to fetch data from external APIs, render the results,\netc - all using TS types.\n\n## Getting it working\n\n```\n$ yarn install\n$ yarn run dev\n```\n\nor whatever tooling you like to use.\n\n## Interesting things\n\nA lot of the fun action is implemented in `GET()` in `src/lib/jsonPlaceholderClient.ts`. This single function will get the passed type (it is a Template/generic function) from the passed resource (we hard-coded it to use jsonplaceholder) and will return that type on success. Failures aren't handled, so I guess they'll just end up in a 500 :-)\n\n## Conclusion\n\nI think svelte and sveltekit is very cool. I am a backend guy so I've not got a ton of experience with FE frameworks but I've been forced to write a lot of JS over the years (with a gun held to my head) and never enjoyed it.\n\nSvelte, I enjoy. It works pretty much the way I expect - there's a couple of little traps - like you can't rename some variables as Svelte treats them as magic variables so you have to always call your `data` variable in int `+page.svelte` that - you can't change it. But it's ok, you might be returning multiple things in `PageData` so forcing that means you won't be refactoring later.\n\nAnyway, hope this helps.\n\n## Halp\n\nI'm sure you are better at svelte, typescript, javascript, than I am. File a PR, I'll merge it. I was looking at implementing a TypeScript version of the [Realworld](https://github.com/gothinkster/realworld) app (the official [Svelte Realworld](https://github.com/sveltejs/realworld) app is in Javascript) but then realised it would take a lot of time so I decided against that. I can see why they didn't do it yet.\n\n## TODO\n\nI wouldn't mind finishing this, having it do all the things.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatjam%2Fsvelte-jsonplaceholder-ts-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatjam%2Fsvelte-jsonplaceholder-ts-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatjam%2Fsvelte-jsonplaceholder-ts-example/lists"}