{"id":15681057,"url":"https://github.com/schniz/httyped","last_synced_at":"2025-05-07T11:42:47.903Z","repository":{"id":66365017,"uuid":"179010361","full_name":"Schniz/httyped","owner":"Schniz","description":"⛓️ Type-safe HTTP client/server communications with awesome autocompletion","archived":false,"fork":false,"pushed_at":"2019-06-17T13:59:18.000Z","size":3160,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T09:41:11.779Z","etag":null,"topics":["express","fetch","http","javascript","typescript"],"latest_commit_sha":null,"homepage":"","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/Schniz.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":"2019-04-02T06:09:20.000Z","updated_at":"2023-04-05T01:25:18.000Z","dependencies_parsed_at":"2023-02-20T16:01:13.657Z","dependency_job_id":null,"html_url":"https://github.com/Schniz/httyped","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Schniz%2Fhttyped","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Schniz%2Fhttyped/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Schniz%2Fhttyped/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Schniz%2Fhttyped/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Schniz","download_url":"https://codeload.github.com/Schniz/httyped/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873675,"owners_count":21817705,"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":["express","fetch","http","javascript","typescript"],"created_at":"2024-10-03T16:48:49.479Z","updated_at":"2025-05-07T11:42:47.885Z","avatar_url":"https://github.com/Schniz.png","language":"TypeScript","readme":"# `httype`\n\n\u003e ⛓️ Type-safe HTTP client/server communications with awesome autocompletion\n\nLet your compiler tell you when you break a contract with your client.\n\n## Features\n\n✅ Awesome autocompletion and type safety for request parts\n\n![autocompletion and type safety on request parts](./docs/autocomplete_params.png)\n\n✅ Nice and simple route documentation\n\n![documentation using types](./docs/route_listing.png)\n\n✅ Compile time and runtime type validation\n\n![Compile-time and runtime type validations](./docs/runtime_type_validations.png)\n\n# Usage\n\n## Route\n\nA route is defined by `RouteDefiner`. This part is shared for both server and client.\n\n:white_check_mark: Supports dynamic parameters\n\n:white_check_mark: Supports a typed request body with [io-ts](https://github.com/gcanti/io-ts)\n\n:white_check_mark: Supports a typed response type with [io-ts](https://github.com/gcanti/io-ts)\n\n#### Examples:\n\n- A `GET` route that returns a `string` output, with a fixed path of `/hello`:\n\n  ```ts\n  RouteDefiner.get.returns(t.string).fixed(\"hello\");\n  ```\n\n- A route that returns a `string` output, with a dynamic path of `/hello/:name`:\n\n  ```ts\n  RouteDefiner.get\n    .returns(t.string)\n    .fixed(\"hello\")\n    .param(\"name\");\n  ```\n\n- A `POST` route that reads a custom type `User` from the request body and returns a custom type `Greeting`:\n\n  ```ts\n  const Greeting = t.type({ msg: t.string });\n  const User = t.type({ name: t.string });\n\n  RouteDefiner.post\n    .reads(User)\n    .returns(Greeting)\n    .fixed(\"user-to-greeting\");\n  ```\n\n## Server\n\nImplementation for servers is by wrapping Express.js\n\n:white_check_mark: Type safe body parsing, thanks to [io-ts](https://github.com/gcanti/io-ts)\n\n:white_check_mark: Awesome autocompletion for routing params and request body\n\n:white_check_mark: Pretty routing table, documentation ready\n\n```ts\nimport { TypedExpress, success } from \"httyped/express\";\nimport express from \"express\";\n\nconst app = express();\nconst typed = TypedExpress.of(app);\n\ntyped.route(\n  RouteDefiner.get // a get request\n    .returns(t.string) // that returns a string\n    .fixed(\"hello\") // and its path is\n    .param(\"name\"), // `/hello/:name`\n  async req =\u003e {\n    return success(`Hello, ${req.params.name}`);\n  }\n);\n\napp.listen(3000);\ntyped.listRoutes(); // Will print a table of routes\n```\n\n## Client\n\nA http client based on `node-fetch`:\n\n:white_check_mark: Type-safety between client and server\n\n:white_check_mark: Autocompletion for request parameters and request body\n\n```ts\nimport { fetcher } from \"httyped/fetch\";\n\nconst User = t.type({ name: string }, \"User\");\n\n// given a route\nconst route = RouteDefiner.post\n  .reads(User)\n  .returns(t.string)\n  .fixed(\"hello\")\n  .param(\"greeting\");\n\nconst fetch = fetcher(route, \"http://localhost:3000\");\n//                           ^ the base URI\n\nconst { status, data } = await fetch({\n  params: {\n    greeting: \"Hello\"\n  },\n  body: {\n    name: \"Gal\"\n  }\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschniz%2Fhttyped","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschniz%2Fhttyped","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschniz%2Fhttyped/lists"}